home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / tests / ChromeTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.8 KB  |  378 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:        ChromeTest.c                                            */
  21. /* Description:    Test for XfeChrome widget.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeTest.h>
  28.  
  29. static Widget    create_chrome        (Widget,String);
  30. static Widget    create_url_bar        (Widget,String);
  31. static Widget    create_tool_box        (Widget,String);
  32. static void        menu_item_cb        (Widget,XtPointer,XtPointer);
  33.  
  34. static void        chrome_toggle        (Widget,XtPointer,XtPointer);
  35. static void        chrome_flash        (Widget,XtPointer,XtPointer);
  36. static void        dash_board_toggle    (Widget,XtPointer,XtPointer);
  37. static void        dash_board_flash    (Widget,XtPointer,XtPointer);
  38.  
  39. /*----------------------------------------------------------------------*/
  40. static XfeMenuItemRec toggle_dash_board_items[] =
  41. {
  42.     { "ToolBar",        XfeMENU_TOGGLE, dash_board_toggle        },
  43.     { "StatusBar",        XfeMENU_TOGGLE, dash_board_toggle        },
  44.     { "ProgressBar",    XfeMENU_TOGGLE, dash_board_toggle        },
  45.     { "TaskBar",        XfeMENU_TOGGLE, dash_board_toggle        },
  46.     { NULL }
  47. };
  48. /*----------------------------------------------------------------------*/
  49. static XfeMenuItemRec flash_dash_board_items[] =
  50. {
  51.     { "ToolBar",        XfeMENU_PUSH, dash_board_flash        },
  52.     { "StatusBar",        XfeMENU_PUSH, dash_board_flash        },
  53.     { "ProgressBar",    XfeMENU_PUSH, dash_board_flash        },
  54.     { "TaskBar",        XfeMENU_PUSH, dash_board_flash        },
  55.     { NULL }
  56. };
  57. /*----------------------------------------------------------------------*/
  58. static XfeMenuItemRec file_items[] =
  59. {
  60.     { "Open",        XfeMENU_PUSH },
  61.     { "Save",        XfeMENU_PUSH },
  62.     { "Sep",        XfeMENU_SEP    },
  63.     { "Exit",        XfeMENU_PUSH,    XfeExitCallback    },
  64.     { NULL }
  65. };
  66. /*----------------------------------------------------------------------*/
  67. static XfeMenuItemRec toggle_items[] =
  68. {
  69.     { "MenuBar",    XfeMENU_TOGGLE, chrome_toggle        },
  70.     { "ToolBox",    XfeMENU_TOGGLE, chrome_toggle        },
  71.     { "DashBoard",    XfeMENU_TOGGLE, chrome_toggle        },
  72.     { "View",        XfeMENU_TOGGLE, chrome_toggle        },
  73.     { "TopView",    XfeMENU_TOGGLE, chrome_toggle        },
  74.     { "BottomView",    XfeMENU_TOGGLE, chrome_toggle        },
  75.     { "Sep",        XfeMENU_SEP    },
  76.     { "DashBoard",    XfeMENU_PANE, NULL,     toggle_dash_board_items    },
  77.     { NULL }
  78. };
  79. /*----------------------------------------------------------------------*/
  80. static XfeMenuItemRec flash_items[] =
  81. {
  82.     { "MenuBar",    XfeMENU_PUSH, chrome_flash        },
  83.     { "ToolBox",    XfeMENU_PUSH, chrome_flash        },
  84.     { "DashBoard",    XfeMENU_PUSH, chrome_flash        },
  85.     { "View",        XfeMENU_PUSH, chrome_flash        },
  86.     { "TopView",    XfeMENU_PUSH, chrome_flash        },
  87.     { "BottomView",    XfeMENU_PUSH, chrome_flash        },
  88.     { "Sep",        XfeMENU_SEP    },
  89.     { "DashBoard",    XfeMENU_PANE, NULL,     flash_dash_board_items    },
  90.     { NULL }
  91. };
  92. /*----------------------------------------------------------------------*/
  93. static XfeMenuItemRec options_items[] =
  94. {
  95.     { "One",    XfeMENU_PUSH        },
  96.     { "Two",    XfeMENU_PUSH        },
  97.     { "Three",    XfeMENU_PUSH        },
  98.     { NULL }
  99. };
  100. /*----------------------------------------------------------------------*/
  101. static XfeMenuItemRec help_items[] =
  102. {
  103.     { "Contents",    XfeMENU_PUSH        },
  104.     { "Search",        XfeMENU_PUSH        },
  105.     { "Sep",        XfeMENU_SEP    },
  106.     { "About",        XfeMENU_PUSH        },
  107.     { NULL }
  108. };
  109. /*----------------------------------------------------------------------*/
  110. static XfeMenuPaneRec pane_items[] =
  111. {
  112.     { "File",        file_items        },
  113.     { "Toggle",        toggle_items    },
  114.     { "Flash",        flash_items    },
  115.     { "Options",    options_items    },
  116.     { "Help",        help_items        },
  117.     { NULL }
  118. };
  119. /*----------------------------------------------------------------------*/
  120. static Widget        _chrome = NULL;
  121.  
  122. static Widget        _menu_bar = NULL;
  123. static Widget        _tool_box = NULL;
  124. static Widget        _dash_board = NULL;
  125. static Widget        _bottom_view = NULL;
  126. static Widget        _center_view = NULL;
  127. static Widget        _left_view = NULL;
  128. static Widget        _right_view = NULL;
  129. static Widget        _top_view = NULL;
  130.  
  131. static Widget        _personal_tool_bar = NULL;
  132. static Widget        _tool_bar = NULL;
  133. static Widget        _url_bar = NULL;
  134.  
  135. /*----------------------------------------------------------------------*/
  136. int
  137. main(int argc,char *argv[])
  138. {
  139.     Widget    form;
  140.     Widget    frame;
  141.  
  142.     XfeAppCreateSimple("ChromeTest",&argc,argv,"MainFrame",&frame,&form);
  143.  
  144.     _menu_bar = XfeMenuBarCreate(form,"MainMenuBar",pane_items,NULL,NULL,0);
  145.  
  146.     _chrome = create_chrome(form,"Chrome");
  147.  
  148.     XtPopup(frame,XtGrabNone);
  149.  
  150.     XfeAppMainLoop();
  151.  
  152.     return 0;
  153. }
  154. /*----------------------------------------------------------------------*/
  155. static Widget
  156. create_url_bar(Widget parent,String name)
  157. {
  158.     Widget url_bar;
  159.     Widget url_form;
  160.     Widget url_label;
  161.     Widget url_text;
  162.     Widget bookmark_button;
  163.  
  164.     url_bar = XtVaCreateManagedWidget(name,
  165.                                       xmFrameWidgetClass,
  166.                                       parent,
  167.                                       NULL);
  168.  
  169.     url_form = XtVaCreateManagedWidget("UrlForm",
  170.                                        xmFormWidgetClass,
  171.                                        url_bar,
  172.                                        NULL);
  173.     
  174.     bookmark_button = XtVaCreateManagedWidget("BookMarkButton",
  175.                                               xfeButtonWidgetClass,
  176.                                               url_form,
  177.                                               XmNleftAttachment, XmATTACH_FORM,
  178.                                               NULL);
  179.  
  180.  
  181.     url_label = XtVaCreateManagedWidget("UrlLabel",
  182.                                         xmLabelWidgetClass,
  183.                                         url_form,
  184.                                         XmNleftAttachment,    XmATTACH_WIDGET,
  185.                                         XmNleftWidget,        bookmark_button,
  186.                                         NULL);
  187.  
  188. #if 1
  189.     url_text = XtVaCreateManagedWidget("UrlText",
  190.                                        xmTextFieldWidgetClass,
  191.                                        url_form,
  192.                                        XmNleftAttachment,    XmATTACH_WIDGET,
  193.                                        XmNleftWidget,        url_label,
  194.                                        XmNrightAttachment,    XmATTACH_FORM,
  195.                                        NULL);
  196. #else
  197.     url_text = XtVaCreateManagedWidget("UrlCombo",
  198.                                        xfeFancyBoxWidgetClass,
  199.                                        url_form,
  200.                                        XmNleftAttachment,    XmATTACH_WIDGET,
  201.                                        XmNleftWidget,        url_label,
  202.                                        XmNrightAttachment,    XmATTACH_FORM,
  203.                                        NULL);
  204. #endif
  205.     
  206.     return url_bar;
  207. }
  208. /*----------------------------------------------------------------------*/
  209. static Widget
  210. create_tool_box(Widget parent,String name)
  211. {
  212.     Widget tool_box;
  213.  
  214.     tool_box = XfeCreateLoadedToolBox(parent,"ToolBox",NULL,0);
  215.  
  216.     XtVaSetValues(tool_box,
  217.                   XmNusePreferredWidth,        False,
  218.                   XmNusePreferredHeight,    True,
  219.                   NULL);
  220.  
  221.     return tool_box;
  222. }
  223. /*----------------------------------------------------------------------*/
  224. static Widget
  225. create_chrome(Widget parent,String name)
  226. {
  227.     Widget chrome;
  228.     Widget menu_bar;
  229.     Widget tool_bar_one;
  230.     Widget url_bar;
  231.     Widget tool_bar_two;
  232.  
  233.     chrome = XtVaCreateManagedWidget(name,
  234.                                       xfeChromeWidgetClass,
  235.                                       parent,
  236.                                       NULL);
  237.  
  238.     menu_bar = XfeMenuBarCreate(chrome,"MenuBar",pane_items,NULL,NULL,0);
  239.  
  240.     XtSetSensitive(menu_bar,False);
  241.  
  242.     _dash_board = XfeCreateLoadedDashBoard(
  243.         chrome,                    /* pw                */
  244.         "DashBoard",            /* name                */
  245.         "S",                    /* tool_prefix        */
  246.         XfeActivateCallback,    /* tool_cb            */
  247.         3,                        /* tool_count        */
  248.         "T",                    /* tool_prefix        */
  249.         False,                    /* tool_large        */
  250.         XfeActivateCallback,    /* tool_cb            */
  251.         4,                        /* tool_count        */
  252.         NULL,                    /* tool_bar_out        */
  253.         NULL,                    /* progress_bar_out    */
  254.         NULL,                    /* status_bar_out    */
  255.         NULL,                    /* task_bar_out        */
  256.         NULL,                    /* tool_items_out    */
  257.         NULL);                    /* task_items_out    */
  258.  
  259.     _tool_box = create_tool_box(chrome,"ToolBox");
  260.  
  261.     tool_bar_one = XfeCreateLoadedToolBar(_tool_box,
  262.                                           "ToolBoxOne",
  263.                                           "One",
  264.                                           10,
  265.                                           2,
  266.                                           XfeArmCallback,
  267.                                           XfeDisarmCallback,
  268.                                           XfeActivateCallback,
  269.                                           NULL);
  270.     
  271.     url_bar = create_url_bar(_tool_box,"UrlBar");
  272.     
  273.     
  274.     tool_bar_two = XfeCreateLoadedToolBar(_tool_box,
  275.                                           "ToolBoxTwo",
  276.                                           "Two",
  277.                                           10,
  278.                                           2,
  279.                                           XfeArmCallback,
  280.                                           XfeDisarmCallback,
  281.                                           XfeActivateCallback,
  282.                                           NULL);
  283.  
  284.     _center_view = XfeCreateFormAndButton(chrome,
  285.                                           "CenterView",
  286.                                           "Center",
  287.                                           20,
  288.                                           False,
  289.                                           NULL,0);
  290.  
  291.     _top_view = XfeCreateFormAndButton(chrome,
  292.                                        "TopView",
  293.                                        "Top",
  294.                                        10,
  295.                                        False,
  296.                                        NULL,0);
  297.     
  298.     _bottom_view = XfeCreateFormAndButton(chrome,
  299.                                           "BottomView",
  300.                                           "Bottom",
  301.                                           10,
  302.                                           False,
  303.                                           NULL,0);
  304.  
  305.     _left_view = XfeCreateFormAndButton(chrome,
  306.                                         "LeftView",
  307.                                         "Left",
  308.                                         10,
  309.                                         False,
  310.                                         NULL,0);
  311.     
  312.     _right_view = XfeCreateFormAndButton(chrome,
  313.                                          "RightView",
  314.                                           "Right",
  315.                                          10,
  316.                                          False,
  317.                                          NULL,0);
  318.     
  319.     return chrome;
  320. }
  321. /*----------------------------------------------------------------------*/
  322. static void
  323. menu_item_cb(Widget w,XtPointer client_data,XtPointer call_data)
  324. {
  325.     int code = (int) client_data;
  326.  
  327.     printf("code = %d\n",code);
  328. }
  329. /*----------------------------------------------------------------------*/
  330. static void
  331. chrome_toggle(Widget w,XtPointer client_data,XtPointer call_data)
  332. {
  333.     String name = XtName(w);
  334.     Widget tw = XfeDescendantFindByName(_chrome,name,XfeFIND_ANY,False);
  335.  
  336.     if (XfeIsAlive(tw))
  337.     {
  338.         XfeWidgetToggleManaged(tw);
  339.     }
  340. }
  341. /*----------------------------------------------------------------------*/
  342. static void
  343. dash_board_toggle(Widget w,XtPointer client_data,XtPointer call_data)
  344. {
  345.     String name = XtName(w);
  346.     Widget tw = XfeDescendantFindByName(_dash_board,name,XfeFIND_ANY,False);
  347.  
  348.     if (XfeIsAlive(tw))
  349.     {
  350.         XfeWidgetToggleManaged(tw);
  351.     }
  352. }
  353. /*----------------------------------------------------------------------*/
  354. static void
  355. chrome_flash(Widget w,XtPointer client_data,XtPointer call_data)
  356. {
  357.     String name = XtName(w);
  358.     Widget tw = XfeDescendantFindByName(_chrome,name,XfeFIND_ANY,False);
  359.  
  360.     if (XfeIsAlive(tw))
  361.     {
  362.         XfeWidgetFlash(tw,400,3);
  363.     }
  364. }
  365. /*----------------------------------------------------------------------*/
  366. static void
  367. dash_board_flash(Widget w,XtPointer client_data,XtPointer call_data)
  368. {
  369.     String name = XtName(w);
  370.     Widget tw = XfeDescendantFindByName(_dash_board,name,XfeFIND_ANY,False);
  371.  
  372.     if (XfeIsAlive(tw))
  373.     {
  374.         XfeWidgetFlash(tw,400,3);
  375.     }
  376. }
  377. /*----------------------------------------------------------------------*/
  378.