home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / tests / PaneTestTwo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  15.3 KB  |  500 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:        PaneTestTwo.c                                            */
  21. /* Description:    Test for XfePane widget.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeTest.h>
  28.  
  29. static void        menu_item_cb                (Widget,XtPointer,XtPointer);
  30. static void        toggle_managed_cb            (Widget,XtPointer,XtPointer);
  31.  
  32. static Widget    create_simple_pane_frame    (String);
  33. static Widget    create_form_and_button        (Widget,unsigned char,
  34.                                              unsigned char,Widget,String,
  35.                                              String,Dimension);
  36.  
  37. /*----------------------------------------------------------------------*/
  38. static XfeMenuItemRec file_items[] =
  39. {
  40.     { "Open",            XfeMENU_PUSH },
  41.     { "Save",            XfeMENU_PUSH },
  42.     { "------------",    XfeMENU_SEP    },
  43.     { "Exit",            XfeMENU_PUSH,    XfeExitCallback    },
  44.     { NULL }
  45. };
  46. /*----------------------------------------------------------------------*/
  47. static XfeMenuItemRec orientation_items[] =
  48. {
  49.     { "OrientationVertical",    XfeMENU_RADIO,        menu_item_cb        },
  50.     { "OrientationHorizontal",    XfeMENU_RADIO,        menu_item_cb        },
  51.     { NULL }
  52. };
  53. /*----------------------------------------------------------------------*/
  54. static XfeMenuItemRec pane_sash_type_items[] =
  55. {
  56.     { "pane_sash_double_line",        XfeMENU_RADIO,        menu_item_cb    },
  57.     { "pane_sash_filled_rectangle",    XfeMENU_RADIO,        menu_item_cb    },
  58.     { "pane_sash_live",                XfeMENU_RADIO,        menu_item_cb    },
  59.     { "pane_sash_rectangle",        XfeMENU_RADIO,        menu_item_cb    },
  60.     { "pane_sash_single_line",        XfeMENU_RADIO,        menu_item_cb    },
  61.     { NULL }
  62. };
  63. /*----------------------------------------------------------------------*/
  64. static XfeMenuItemRec button_boolean_items[] =
  65. {
  66.     { "TraversalOn",            XfeMENU_TOGGLE,        menu_item_cb        },
  67.     { "------------",            XfeMENU_SEP    },
  68.     { "Sensitive",                XfeMENU_TOGGLE,        menu_item_cb        },
  69.     { "------------",            XfeMENU_SEP    },
  70.     { "UsePreferredWidth",        XfeMENU_TOGGLE,        menu_item_cb        },
  71.     { "UsePreferredHeight",        XfeMENU_TOGGLE,        menu_item_cb        },
  72.     { NULL }
  73. };
  74. /*----------------------------------------------------------------------*/
  75. static XfeMenuItemRec misc_items[] =
  76. {
  77.     { "Orientation",    XfeMENU_PANE,    NULL,    orientation_items        },
  78.     { "PaneSashType",    XfeMENU_PANE,    NULL,    pane_sash_type_items    },
  79.     { NULL }
  80. };
  81. /*----------------------------------------------------------------------*/
  82. static XfeMenuItemRec dimension_items[] =
  83. {
  84.     { "0",                XfeMENU_RADIO,        menu_item_cb        },
  85.     { "1",                XfeMENU_RADIO,        menu_item_cb        },
  86.     { "2",                XfeMENU_RADIO,        menu_item_cb        },
  87.     { "3",                XfeMENU_RADIO,        menu_item_cb        },
  88.     { "4",                XfeMENU_RADIO,        menu_item_cb        },
  89.     { "5",                XfeMENU_RADIO,        menu_item_cb        },
  90.     { "6",                XfeMENU_RADIO,        menu_item_cb        },
  91.     { "7",                XfeMENU_RADIO,        menu_item_cb        },
  92.     { "8",                XfeMENU_RADIO,        menu_item_cb        },
  93.     { "9",                XfeMENU_RADIO,        menu_item_cb        },
  94.     { "10",                XfeMENU_RADIO,        menu_item_cb        },
  95.     { "20",                XfeMENU_RADIO,        menu_item_cb        },
  96.     { "30",                XfeMENU_RADIO,        menu_item_cb        },
  97.     { "40",                XfeMENU_RADIO,        menu_item_cb        },
  98.     { "50",                XfeMENU_RADIO,        menu_item_cb        },
  99.     { "100",            XfeMENU_RADIO,        menu_item_cb        },
  100.     { "200",            XfeMENU_RADIO,        menu_item_cb        },
  101.     { "300",            XfeMENU_RADIO,        menu_item_cb        },
  102.     { "400",            XfeMENU_RADIO,        menu_item_cb        },
  103.     { "500",            XfeMENU_RADIO,        menu_item_cb        },
  104.     { "1000",            XfeMENU_RADIO,        menu_item_cb        },
  105.     { NULL }
  106. };
  107. /*----------------------------------------------------------------------*/
  108. static XfeMenuItemRec margin_items[] =
  109. {
  110.     { "MarginLeft",        XfeMENU_PANE,        NULL, dimension_items        },
  111.     { "MarginRight",    XfeMENU_PANE,        NULL, dimension_items        },
  112.     { "MarginTop",        XfeMENU_PANE,        NULL, dimension_items        },
  113.     { "MarginBottom",    XfeMENU_PANE,        NULL, dimension_items        },
  114.     { "------------",    XfeMENU_SEP    },
  115.     { "MarginAll"    ,    XfeMENU_PANE,        NULL, dimension_items        },
  116.     { NULL }
  117. };
  118. /*----------------------------------------------------------------------*/
  119. static XfeMenuItemRec managing_items[] =
  120. {
  121.     { "One"            ,        XfeMENU_TOGGLE,        menu_item_cb        },
  122.     { "OneTop"        ,        XfeMENU_TOGGLE,        menu_item_cb        },
  123.     { "OneBottom"    ,        XfeMENU_TOGGLE,        menu_item_cb        },
  124.     { "OneLeft"        ,        XfeMENU_TOGGLE,        menu_item_cb        },
  125.     { "OneRight"    ,        XfeMENU_TOGGLE,        menu_item_cb        },
  126.     { "------------",        XfeMENU_SEP    },
  127.     { "Two"            ,        XfeMENU_TOGGLE,        menu_item_cb        },
  128.     { "TwoTop"        ,        XfeMENU_TOGGLE,        menu_item_cb        },
  129.     { "TwoBottom"    ,        XfeMENU_TOGGLE,        menu_item_cb        },
  130.     { "TwoLeft"        ,        XfeMENU_TOGGLE,        menu_item_cb        },
  131.     { "TwoRight"    ,        XfeMENU_TOGGLE,        menu_item_cb        },
  132.     { NULL }
  133. };
  134. /*----------------------------------------------------------------------*/
  135. static XfeMenuItemRec dimensions_items[] =
  136. {
  137.     { "Width",                    XfeMENU_PANE,        NULL, dimension_items    },
  138.     { "Height",                    XfeMENU_PANE,        NULL, dimension_items    },
  139.     { "------------",            XfeMENU_SEP    },
  140.     { "HighlightThickness",        XfeMENU_PANE,        NULL, dimension_items    },
  141.     { "ShadowThickness",        XfeMENU_PANE,        NULL, dimension_items    },
  142.     { "------------",            XfeMENU_SEP    },
  143.     { "SashOffset",                XfeMENU_PANE,        NULL, dimension_items    },
  144.     { "SashShadowThickness",    XfeMENU_PANE,        NULL, dimension_items    },
  145.     { "SashSpacing",            XfeMENU_PANE,        NULL, dimension_items    },
  146.     { "SashThickness",            XfeMENU_PANE,        NULL, dimension_items    },
  147.     { "------------",            XfeMENU_SEP    },
  148.     { "Margins",                XfeMENU_PANE,        NULL, margin_items        },
  149.     { "RaiseBorderThickness",    XfeMENU_PANE,        NULL, dimension_items    },
  150.     { "------------",            XfeMENU_SEP    },
  151.     { "ArmOffset",                XfeMENU_PANE,        NULL, dimension_items    },
  152.     { "------------",            XfeMENU_SEP    },
  153.     { "SashPosition",            XfeMENU_PANE,        NULL, dimension_items    },
  154.     { NULL }
  155. };
  156. /*----------------------------------------------------------------------*/
  157. static XfeMenuPaneRec pane_items[] =
  158. {
  159.     { "File",            file_items                },
  160.     { "Managing",        managing_items            },
  161.     { "Dimensions",        dimensions_items        },
  162.     { "BooleanItems",    button_boolean_items    },
  163.     { "MiscItems",        misc_items                },
  164.     { NULL }
  165. };
  166. /*----------------------------------------------------------------------*/
  167.  
  168. /*----------------------------------------------------------------------*/
  169. int
  170. main(int argc,char *argv[])
  171. {
  172.     Widget    simple_frame;
  173.  
  174.     XfeAppCreate("PaneTestTwo",&argc,argv);
  175.  
  176.     simple_frame = create_simple_pane_frame("Frame");
  177.  
  178.     XtPopup(simple_frame,XtGrabNone);
  179.  
  180.     XfeAppMainLoop();
  181.  
  182.     return 0;
  183. }
  184. /*----------------------------------------------------------------------*/
  185. static Widget
  186. create_simple_pane_frame(String frame_name)
  187. {
  188.     Widget    frame;
  189.     Widget    form;
  190.     Widget    menu;
  191.  
  192.     Widget    pane;
  193.  
  194.     Widget    one;
  195.     Widget    two;
  196.  
  197.     frame = XfeFrameCreate(frame_name,NULL,0);
  198.  
  199.     form = XfeDescendantFindByName(frame,"MainForm",XfeFIND_ANY,False);
  200.  
  201.     pane = XtVaCreateManagedWidget("Pane",xfePaneWidgetClass,form,NULL);
  202.  
  203.     menu = XfeMenuBarCreate(form,"MenuBar",pane_items,(XtPointer) pane,NULL,0);
  204.  
  205.     one =  XtVaCreateManagedWidget("One",xmFormWidgetClass,pane,NULL);
  206.  
  207.       two =  XtVaCreateManagedWidget("Two",xmFormWidgetClass,pane,NULL);
  208.  
  209.     create_form_and_button(pane,
  210.                            XmPANE_CHILD_ATTACHMENT_ONE,
  211.                            XmPANE_CHILD_ATTACH_TOP,
  212.                            one,"OneTop","Top",2);
  213.  
  214.     create_form_and_button(pane,
  215.                            XmPANE_CHILD_ATTACHMENT_ONE,
  216.                            XmPANE_CHILD_ATTACH_BOTTOM,
  217.                            one,"OneBottom","Bottom",2);
  218.  
  219.     create_form_and_button(pane,
  220.                            XmPANE_CHILD_ATTACHMENT_ONE,
  221.                            XmPANE_CHILD_ATTACH_LEFT,
  222.                            one,"OneLeft","Left",2);
  223.  
  224.     create_form_and_button(pane,
  225.                            XmPANE_CHILD_ATTACHMENT_ONE,
  226.                            XmPANE_CHILD_ATTACH_RIGHT,
  227.                            one,"OneRight","Right",2);
  228.  
  229.     create_form_and_button(pane,
  230.                            XmPANE_CHILD_ATTACHMENT_TWO,
  231.                            XmPANE_CHILD_ATTACH_TOP,
  232.                            two,"TwoTop","Top",2);
  233.  
  234.     create_form_and_button(pane,
  235.                            XmPANE_CHILD_ATTACHMENT_TWO,
  236.                            XmPANE_CHILD_ATTACH_BOTTOM,
  237.                            two,"TwoBottom","Bottom",2);
  238.  
  239.     create_form_and_button(pane,
  240.                            XmPANE_CHILD_ATTACHMENT_TWO,
  241.                            XmPANE_CHILD_ATTACH_LEFT,
  242.                            two,"TwoLeft","Left",2);
  243.  
  244.     create_form_and_button(pane,
  245.                            XmPANE_CHILD_ATTACHMENT_TWO,
  246.                            XmPANE_CHILD_ATTACH_RIGHT,
  247.                            two,"TwoRight","Right",2);
  248.     return frame;
  249. }
  250. /*----------------------------------------------------------------------*/
  251. static void
  252. menu_item_cb(Widget w,XtPointer client_data,XtPointer call_data)
  253. {
  254.     Widget        pane = (Widget) client_data;
  255.     String        name = XtName(w);
  256.     String        parent_name = XtName(XtParent(w));
  257.     Arg            av[20];
  258.     Cardinal    ac = 0;
  259.  
  260.     printf("menu_item_cb(%s,%s) pane = %s\n",name,parent_name,XtName(pane));
  261.  
  262.     if (!XfeIsAlive(pane))
  263.     {
  264.         return;
  265.     }
  266.  
  267.     if (strcmp(name,"TraversalOn") == 0)
  268.     {
  269.         XfeResourceToggleBoolean(pane,XmNtraversalOn);
  270.     }
  271.     else if (strcmp(name,"pane_sash_double_line") == 0)
  272.     {
  273.         XtSetArg(av[ac],XmNpaneSashType,XmPANE_SASH_DOUBLE_LINE); ac++;
  274.     }
  275.     else if (strcmp(name,"pane_sash_live") == 0)
  276.     {
  277.         XtSetArg(av[ac],XmNpaneSashType,XmPANE_SASH_LIVE); ac++;
  278.     }
  279.     else if (strcmp(name,"pane_sash_rectangle") == 0)
  280.     {
  281.         XtSetArg(av[ac],XmNpaneSashType,XmPANE_SASH_RECTANGLE); ac++;
  282.     }
  283.     else if (strcmp(name,"pane_sash_filled_rectangle") == 0)
  284.     {
  285.         XtSetArg(av[ac],XmNpaneSashType,XmPANE_SASH_FILLED_RECTANGLE); ac++;
  286.     }
  287.     else if (strcmp(name,"pane_sash_single_line") == 0)
  288.     {
  289.         XtSetArg(av[ac],XmNpaneSashType,XmPANE_SASH_SINGLE_LINE); ac++;
  290.     }
  291.     else if (strcmp(name,"Sensitive") == 0)
  292.     {
  293.         XfeResourceToggleBoolean(pane,XmNsensitive);
  294.     }
  295.     else if (strcmp(name,"UsePreferredWidth") == 0)
  296.     {
  297.         XfeResourceToggleBoolean(pane,XmNusePreferredWidth);
  298.     }
  299.     else if (strcmp(name,"UsePreferredHeight") == 0)
  300.     {
  301.         XfeResourceToggleBoolean(pane,XmNusePreferredHeight);
  302.     }
  303.     else if (strcmp(name,"ShadowIn") == 0)
  304.     {
  305.         XtSetArg(av[ac],XmNshadowType,XmSHADOW_IN); ac++;
  306.     }
  307.     else if (strcmp(name,"ShadowOut") == 0)
  308.     {
  309.         XtSetArg(av[ac],XmNshadowType,XmSHADOW_OUT); ac++;
  310.     }
  311.     else if (strcmp(name,"ShadowEtchedIn") == 0)
  312.     {
  313.         XtSetArg(av[ac],XmNshadowType,XmSHADOW_ETCHED_IN); ac++;
  314.     }
  315.     else if (strcmp(name,"ShadowEtchedOut") == 0)
  316.     {
  317.         XtSetArg(av[ac],XmNshadowType,XmSHADOW_ETCHED_OUT); ac++;
  318.     }
  319.     else if (strcmp(name,"AlignmentBeginning") == 0)
  320.     {
  321.         XtSetArg(av[ac],XmNlabelAlignment,XmALIGNMENT_BEGINNING); ac++;
  322.     }
  323.     else if (strcmp(name,"AlignmentCenter") == 0)
  324.     {
  325.         XtSetArg(av[ac],XmNlabelAlignment,XmALIGNMENT_CENTER); ac++;
  326.     }
  327.     else if (strcmp(name,"AlignmentEnd") == 0)
  328.     {
  329.         XtSetArg(av[ac],XmNlabelAlignment,XmALIGNMENT_END); ac++;
  330.     }
  331.  
  332.     if (strcmp(parent_name,"MarginLeft") == 0)
  333.     {
  334.         XtSetArg(av[ac],XmNmarginLeft,atoi(name)); ac++;
  335.     }
  336.     else if (strcmp(parent_name,"MarginRight") == 0)
  337.     {
  338.         XtSetArg(av[ac],XmNmarginRight,atoi(name)); ac++;
  339.     }
  340.     else if (strcmp(parent_name,"MarginTop") == 0)
  341.     {
  342.         XtSetArg(av[ac],XmNmarginTop,atoi(name)); ac++;
  343.     }
  344.     else if (strcmp(parent_name,"MarginBottom") == 0)
  345.     {
  346.         XtSetArg(av[ac],XmNmarginBottom,atoi(name)); ac++;
  347.     }
  348.     else if (strcmp(parent_name,"MarginAll") == 0)
  349.     {
  350.         XtSetArg(av[ac],XmNmarginLeft,atoi(name)); ac++;
  351.         XtSetArg(av[ac],XmNmarginRight,atoi(name)); ac++;
  352.         XtSetArg(av[ac],XmNmarginTop,atoi(name)); ac++;
  353.         XtSetArg(av[ac],XmNmarginBottom,atoi(name)); ac++;
  354.     }
  355.     else if (strcmp(parent_name,"Width") == 0)
  356.     {
  357.         XtSetArg(av[ac],XmNwidth,atoi(name)); ac++;
  358.     }
  359.     else if (strcmp(parent_name,"Height") == 0)
  360.     {
  361.         XtSetArg(av[ac],XmNheight,atoi(name)); ac++;
  362.     }
  363.     else if (strcmp(parent_name,"ShadowThickness") == 0)
  364.     {
  365.         XtSetArg(av[ac],XmNshadowThickness,atoi(name)); ac++;
  366.     }
  367.     else if (strcmp(parent_name,"SashOffset") == 0)
  368.     {
  369.         XtSetArg(av[ac],XmNsashOffset,atoi(name)); ac++;
  370.     }
  371.     else if (strcmp(parent_name,"SashSpacing") == 0)
  372.     {
  373.         XtSetArg(av[ac],XmNsashSpacing,atoi(name)); ac++;
  374.     }
  375.     else if (strcmp(parent_name,"SashThickness") == 0)
  376.     {
  377.         XtSetArg(av[ac],XmNsashThickness,atoi(name)); ac++;
  378.     }
  379.     else if (strcmp(parent_name,"SashShadowThickness") == 0)
  380.     {
  381.         XtSetArg(av[ac],XmNsashShadowThickness,atoi(name)); ac++;
  382.     }
  383.     else if (strcmp(parent_name,"HighlightThickness") == 0)
  384.     {
  385.         XtSetArg(av[ac],XmNhighlightThickness,atoi(name)); ac++;
  386.     }
  387.     else if (strcmp(parent_name,"RaiseBorderThickness") == 0)
  388.     {
  389.         XtSetArg(av[ac],XmNraiseBorderThickness,atoi(name)); ac++;
  390.     }
  391.     else if (strcmp(parent_name,"ArmOffset") == 0)
  392.     {
  393.         XtSetArg(av[ac],XmNarmOffset,atoi(name)); ac++;
  394.     }
  395.     else if (strcmp(name,"OrientationVertical") == 0)
  396.     {
  397.         XtSetArg(av[ac],XmNorientation,XmVERTICAL); ac++;
  398.     }
  399.     else if (strcmp(name,"OrientationHorizontal") == 0)
  400.     {
  401.         XtSetArg(av[ac],XmNorientation,XmHORIZONTAL); ac++;
  402.     }
  403.     else if (strcmp(parent_name,"Managing") == 0)
  404.     {
  405.         Widget child = XfeDescendantFindByName(pane,name,XfeFIND_ANY,False);
  406.  
  407.         if (XfeIsAlive(child))
  408.         {
  409.             XfeToggleManagedState(child);
  410.         }
  411.     }
  412.     else if (strcmp(parent_name,"SashPosition") == 0)
  413.     {
  414.         XtSetArg(av[ac],XmNsashPosition,atoi(name)); ac++;
  415.     }
  416.  
  417.     if (ac)
  418.     {
  419.         XtSetValues(pane,av,ac);
  420.     }
  421. }
  422. /*----------------------------------------------------------------------*/
  423. static void
  424. toggle_managed_cb(Widget w,XtPointer client_data,XtPointer call_data)
  425. {
  426.     Widget        pane = (Widget) client_data;
  427.  
  428.     if (XfeIsAlive(pane))
  429.     {
  430.         XfeToggleManagedState(pane);
  431.  
  432.         if (XfeIsArrow(w))
  433.         {
  434.             unsigned char arrow_direction;
  435.  
  436.             XtVaGetValues(w,XmNarrowDirection,&arrow_direction,NULL);
  437.  
  438.             if (arrow_direction == XmARROW_DOWN)
  439.             {
  440.                 arrow_direction = XmARROW_UP;
  441.             }
  442.             else if (arrow_direction == XmARROW_UP)
  443.             {
  444.                 arrow_direction = XmARROW_DOWN;
  445.             }
  446.             else if (arrow_direction == XmARROW_RIGHT)
  447.             {
  448.                 arrow_direction = XmARROW_LEFT;
  449.             }
  450.             else if (arrow_direction == XmARROW_LEFT)
  451.             {
  452.                 arrow_direction = XmARROW_RIGHT;
  453.             }
  454.  
  455.             XtVaSetValues(w,XmNarrowDirection,arrow_direction,NULL);
  456.         }
  457.     }
  458. }
  459. /*----------------------------------------------------------------------*/
  460. static Widget
  461. create_form_and_button(Widget            pw,
  462.                        unsigned char    child_type,
  463.                        unsigned char    child_attachment,
  464.                        Widget            target,
  465.                        String            form_name,
  466.                        String            button_name,
  467.                        Dimension        offset)
  468. {
  469.     Widget        form = NULL;
  470.     Widget        button = NULL;
  471.     Arg            av[20];
  472.     Cardinal    ac = 0;
  473.  
  474.     XtSetArg(av[ac],XmNpaneChildType,        child_type);        ac++;
  475.     XtSetArg(av[ac],XmNpaneChildAttachment,    child_attachment);    ac++;
  476.      XtSetArg(av[ac],XmNalwaysVisible,        True);                ac++;
  477.  
  478. #if 1
  479.  
  480.      form = XfeCreateFormAndButton(pw,form_name,button_name,offset,True,av,ac);
  481.  
  482.     button = XfeDescendantFindByName(form,button_name,XfeFIND_ANY,False);
  483.  
  484.     assert( XfeIsAlive(button) );
  485.  
  486.     XtAddCallback(button,XmNactivateCallback,toggle_managed_cb,target);
  487.  
  488. #else
  489.  
  490.      XtSetArg(av[ac],XmNwidth,                20);                ac++;
  491.      XtSetArg(av[ac],XmNheight,                20);                ac++;
  492.  
  493.     form = XtCreateManagedWidget(form_name,xmFormWidgetClass,pw,av,ac);
  494.  
  495. #endif
  496.  
  497.     return form;
  498. }
  499. /*----------------------------------------------------------------------*/
  500.