home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / tests / FrameShellTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.3 KB  |  278 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:        FrameShellTest.c                                        */
  21. /* Description:    Test for XfeFrameShell widget.                            */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27.  
  28. #include <Xfe/XfeTest.h>
  29.  
  30. static Widget    create_control        (String);
  31. static Widget    create_dummy        (String);
  32.  
  33. static void        first_map_cb        (Widget,XtPointer,XtPointer);
  34. static void        map_cb                (Widget,XtPointer,XtPointer);
  35. static void        unmap_cb            (Widget,XtPointer,XtPointer);
  36.  
  37. static void        track_cb            (Widget,XtPointer,XtPointer);
  38. static void        operation_cb        (Widget,XtPointer,XtPointer);
  39.  
  40. static void        message_output        (String);
  41. static String    message_create        (Widget,String);
  42.  
  43. /*----------------------------------------------------------------------*/
  44. static XfeMenuItemRec file_items[] =
  45. {
  46.     { "Open",        XfeMENU_PUSH },
  47.     { "Save",        XfeMENU_PUSH },
  48.     { "Sep",        XfeMENU_SEP    },
  49.     { "Exit",        XfeMENU_PUSH,    XfeExitCallback    },
  50.     { NULL }
  51. };
  52. /*----------------------------------------------------------------------*/
  53. static XfeMenuItemRec track_items[] =
  54. {
  55.     { "Editres",        XfeMENU_TOGGLE,        track_cb        },
  56.     { "DeleteWindow",    XfeMENU_TOGGLE,        track_cb        },
  57.     { "SaveYourself",    XfeMENU_TOGGLE,        track_cb        },
  58.     { "Mapping",        XfeMENU_TOGGLE,        track_cb        },
  59.     { "Position",        XfeMENU_TOGGLE,        track_cb        },
  60.     { "Size",            XfeMENU_TOGGLE,        track_cb        },
  61.     { NULL }
  62. };
  63. /*----------------------------------------------------------------------*/
  64. static XfeMenuItemRec operations_items[] =
  65. {
  66.     { "Popup",        XfeMENU_PUSH, operation_cb        },
  67.     { "Popdown",    XfeMENU_PUSH, operation_cb        },
  68.     { "Sep",        XfeMENU_SEP    },
  69.     { "Map",        XfeMENU_PUSH, operation_cb        },
  70.     { "Unmap",        XfeMENU_PUSH, operation_cb        },
  71.     { "Realize",        XfeMENU_PUSH, operation_cb        },
  72.     { "Sep",        XfeMENU_SEP    },
  73.     { "Raise",        XfeMENU_PUSH, operation_cb        },
  74.     { "Lower",        XfeMENU_PUSH, operation_cb        },
  75.     { "Sep",        XfeMENU_SEP    },
  76.     { "Destroy",    XfeMENU_PUSH, operation_cb        },
  77.     { "Create",        XfeMENU_PUSH, operation_cb        },
  78.     { NULL }
  79. };
  80. /*----------------------------------------------------------------------*/
  81. static XfeMenuPaneRec pane_items[] =
  82. {
  83.     { "File",        file_items            },
  84.     { "Track",        track_items            },
  85.     { "Operations",    operations_items    },
  86.     { NULL }
  87. };
  88. /*----------------------------------------------------------------------*/
  89.  
  90. static Widget _control = NULL;
  91. static Widget _dummy = NULL;
  92. static Widget _tool_bar = NULL;
  93. static Widget _log_list = NULL;
  94.  
  95. /*----------------------------------------------------------------------*/
  96. int
  97. main(int argc,char *argv[])
  98. {
  99.     XfeAppCreate("FrameShellTest",&argc,argv);
  100.  
  101.     _control = create_control("Control");
  102.  
  103.     _dummy = create_dummy("Dummy");
  104.  
  105.     _tool_bar = XfeDescendantFindByName(_control,"ToolBar",XfeFIND_ANY,False);
  106.  
  107.     _log_list = XfeDescendantFindByName(_control,"List",XfeFIND_ANY,False);
  108.  
  109. /*     XtPopup(_dummy,XtGrabNone); */
  110.     
  111.     XtPopup(_control,XtGrabNone);
  112.  
  113.     XfeAppMainLoop();
  114.  
  115.     return 0;
  116. }
  117. /*----------------------------------------------------------------------*/
  118. static Widget
  119. create_control(String name)
  120. {
  121.     Widget        frame = NULL;
  122.     Widget        form = NULL;
  123.     Widget        tool_bar;
  124.     Widget        list;
  125.     Arg            av[20];
  126.     Cardinal    ac = 0;
  127.  
  128.     
  129.     XtSetArg(av[ac],XmNtrackEditres,False); ac++;
  130.  
  131.     frame = XfeFrameCreate(name,av,ac);
  132.     
  133.     form = XfeDescendantFindByName(frame,"MainForm",XfeFIND_ANY,False);
  134.  
  135.     tool_bar = XfeToolBarCreate(form,"ToolBar",pane_items,NULL);
  136.  
  137.     list = XmCreateScrolledList(form,"List",NULL,0);
  138.  
  139.     XtManageChild(list);
  140.  
  141.     return frame;
  142. }
  143. /*----------------------------------------------------------------------*/
  144. static Widget
  145. create_dummy(String name)
  146. {
  147.     Widget frame = NULL;
  148.     Widget form = NULL;
  149.  
  150.     frame = XfeFrameCreate(name,NULL,0);
  151.     
  152.     form = XfeDescendantFindByName(frame,"MainForm",XfeFIND_ANY,False);
  153.  
  154.     XtAddCallback(frame,XmNfirstMapCallback,first_map_cb,NULL);
  155.     XtAddCallback(frame,XmNmapCallback,map_cb,NULL);
  156.     XtAddCallback(frame,XmNunmapCallback,unmap_cb,NULL);
  157.  
  158.     return frame;
  159. }
  160. /*----------------------------------------------------------------------*/
  161. static void
  162. first_map_cb(Widget w,XtPointer client_data,XtPointer call_data)
  163. {
  164.     message_output(message_create(w,"FirstMap"));
  165. }
  166. /*----------------------------------------------------------------------*/
  167. static void
  168. map_cb(Widget w,XtPointer client_data,XtPointer call_data)
  169. {
  170.     message_output(message_create(w,"Map"));
  171. }
  172. /*----------------------------------------------------------------------*/
  173. static void
  174. unmap_cb(Widget w,XtPointer client_data,XtPointer call_data)
  175. {
  176.     message_output(message_create(w,"Unmap"));
  177. }
  178. /*----------------------------------------------------------------------*/
  179. static void
  180. track_cb(Widget w,XtPointer client_data,XtPointer call_data)
  181. {
  182.     String name = XtName(w);
  183.  
  184.     if (!XfeIsAlive(_dummy))
  185.     {
  186.         return;
  187.     }
  188.  
  189.     if (strcmp(name,"Editres") == 0)
  190.     {
  191.         XfeResourceToggleBoolean(_dummy,XmNtrackEditres);
  192.     }
  193.     else if (strcmp(name,"DeleteWindow") == 0)
  194.     {
  195.         XfeResourceToggleBoolean(_dummy,XmNtrackDeleteWindow);
  196.     }
  197.     else if (strcmp(name,"Mapping") == 0)
  198.     {
  199.         XfeResourceToggleBoolean(_dummy,XmNtrackMapping);
  200.     }
  201. }
  202. /*----------------------------------------------------------------------*/
  203. static void
  204. operation_cb(Widget w,XtPointer client_data,XtPointer call_data)
  205. {
  206.     String name = XtName(w);
  207.  
  208.     if (!XfeIsAlive(_dummy))
  209.     {
  210.         return;
  211.     }
  212.  
  213.     if (strcmp(name,"Popup") == 0)
  214.     {
  215.         XtPopup(_dummy,XtGrabNone);
  216.     }
  217.     else if (strcmp(name,"Popdown") == 0)
  218.     {
  219.         XtPopdown(_dummy);
  220.     }
  221.     else if (strcmp(name,"Map") == 0)
  222.     {
  223.         XtMapWidget(_dummy);
  224.     }
  225.     else if (strcmp(name,"Unmap") == 0)
  226.     {
  227.         XtUnmapWidget(_dummy);
  228.     }
  229.     else if (strcmp(name,"Realize") == 0)
  230.     {
  231.         XtRealizeWidget(_dummy);
  232.     }
  233. }
  234. /*----------------------------------------------------------------------*/
  235. static void
  236. message_output(String message)
  237. {
  238.     XmString item;
  239.  
  240.     assert( XfeIsAlive(_log_list) );
  241.  
  242.     if (!message)
  243.     {
  244.         message = "NULL";
  245.     }
  246.  
  247.     item = XmStringCreate(message,XmFONTLIST_DEFAULT_TAG);
  248.  
  249.     XmListAddItem(_log_list,item,0);
  250.  
  251.     XmStringFree(item);
  252. }
  253. /*----------------------------------------------------------------------*/
  254. static String
  255. message_create(Widget w,String message)
  256. {
  257.     String name;
  258.  
  259.     static char buf[4096];
  260.     static int count = 1;
  261.  
  262.     if (XfeIsAlive(w))
  263.     {
  264.         name = XtName(w);
  265.     }
  266.     else
  267.     {
  268.         name = "NULL";
  269.     }
  270.  
  271.     sprintf(buf,"%3d. %s(%s)",count,message,name);
  272.  
  273.     count++;
  274.  
  275.     return buf;
  276. }
  277. /*----------------------------------------------------------------------*/
  278.