home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / XfeTest / TestApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.5 KB  |  196 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/TestApp.c>                                        */
  21. /* Description:    Xfe widget tests stuff.                                    */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeTest.h>
  28.  
  29. #include <X11/Xmu/Editres.h>
  30. #include <X11/Xmu/Converters.h>
  31.  
  32. #include <X11/IntrinsicP.h>
  33.  
  34. static XtConvertArgRec parentCvtArg[] = 
  35. {
  36.     {
  37.         XtWidgetBaseOffset,
  38.         (XtPointer) XtOffsetOf(WidgetRec , core . parent),
  39.         sizeof(Widget)
  40.     }
  41. };
  42.  
  43. /*----------------------------------------------------------------------*/
  44. static XtAppContext        _xfe_app_context = NULL;
  45. static Widget            _xfe_app_shell = NULL;
  46. /*----------------------------------------------------------------------*/
  47.  
  48. extern char * fallback_resources[];
  49.  
  50. /*----------------------------------------------------------------------*/
  51. /* extern */ void
  52. XfeAppCreate(char * app_name,int * argc,String * argv)
  53. {
  54.     assert( _xfe_app_context == NULL );
  55.     assert( _xfe_app_shell == NULL );
  56.     
  57.     _xfe_app_shell = XtAppInitialize(&_xfe_app_context,app_name,
  58.                                      NULL,0,argc,argv,
  59.                                      fallback_resources,
  60.                                      NULL,0);
  61.  
  62.     XtVaSetValues(_xfe_app_shell,
  63.                     XmNmappedWhenManaged,        False,
  64.                   XmNx,                        XfeScreenWidth(_xfe_app_shell)/2,
  65.                   XmNy,                        XfeScreenHeight(_xfe_app_shell)/2,
  66.                   XmNwidth,                    1,
  67.                   XmNheight,                1,
  68.                   NULL);
  69.  
  70. /*     XfeAddEditresSupport(_xfe_app_shell); */
  71.     XfeRegisterStringToWidgetCvt();
  72. }
  73. /*----------------------------------------------------------------------*/
  74. /* extern */ void
  75. XfeAppCreateSimple(char *        app_name,
  76.                    int *        argc,
  77.                    String *        argv,
  78.                    char *        frame_name,
  79.                    Widget *        frame_out,
  80.                    Widget *        form_out)
  81. {
  82.     assert( _xfe_app_context == NULL );
  83.     assert( _xfe_app_shell == NULL );
  84.     assert( frame_out != NULL );
  85.     assert( form_out != NULL );
  86.  
  87.     XfeAppCreate(app_name,argc,argv);
  88.  
  89.     *frame_out = XfeFrameCreate(frame_name,NULL,0);
  90.  
  91.     *form_out = XfeDescendantFindByName(*frame_out,
  92.                                         "MainForm",
  93.                                         XfeFIND_ANY,False);
  94. }
  95. /*----------------------------------------------------------------------*/
  96. /* extern */ Widget
  97. XfeFrameCreate(char * frame_name,ArgList args,Cardinal num_args)
  98. {
  99.     Widget frame;
  100.     Widget main_form;
  101.  
  102.     assert( _xfe_app_context != NULL );
  103.     assert( XfeIsAlive(_xfe_app_shell) );
  104.  
  105.     frame = XtVaCreatePopupShell(frame_name,
  106.                                  xfeFrameShellWidgetClass,
  107.                                  _xfe_app_shell,
  108.                                  NULL);
  109.     
  110.     main_form = XfeCreateManagedForm(frame,"MainForm",NULL,0);
  111.  
  112.       XfeAddEditresSupport(frame);
  113.  
  114.     return frame;
  115. }
  116. /*----------------------------------------------------------------------*/
  117. /* extern */ Widget
  118. XfeFrameCreateWithChrome(char * frame_name,ArgList args,Cardinal num_args)
  119. {
  120.     Widget frame;
  121.     Widget chrome;
  122.  
  123.     assert( _xfe_app_context != NULL );
  124.     assert( XfeIsAlive(_xfe_app_shell) );
  125.  
  126.     frame = XtVaCreatePopupShell(frame_name,
  127.                                  xfeFrameShellWidgetClass,
  128.                                  _xfe_app_shell,
  129.                                  NULL);
  130.     
  131.     chrome = XtVaCreateManagedWidget("Chrome",
  132.                                      xfeChromeWidgetClass,
  133.                                      frame,
  134.                                      NULL);
  135.  
  136.       XfeAddEditresSupport(frame);
  137.  
  138.     return frame;
  139. }
  140. /*----------------------------------------------------------------------*/
  141. /* extern */ void
  142. XfeAddEditresSupport(Widget shell)
  143. {
  144.     assert( XfeIsAlive(shell) );
  145.     assert( XtIsShell(shell) );
  146.  
  147.     XtAddEventHandler(shell,0,True,_XEditResCheckMessages,NULL);
  148. }
  149. /*----------------------------------------------------------------------*/
  150. /* extern */ void
  151. XfeRegisterStringToWidgetCvt(void)
  152. {
  153.     XtSetTypeConverter(XtRString,
  154.                        XtRWidget,
  155.                        XmuNewCvtStringToWidget,
  156.                        parentCvtArg,
  157.                        XtNumber(parentCvtArg),
  158.                        XtCacheNone,
  159.                        NULL);
  160. }
  161. /*----------------------------------------------------------------------*/
  162. /* extern */ XtAppContext
  163. XfeAppContext(void)
  164. {
  165.     assert( _xfe_app_context != NULL );
  166.  
  167.     return _xfe_app_context;
  168. }
  169. /*----------------------------------------------------------------------*/
  170. /* extern */ Widget
  171. XfeAppShell(void)
  172. {
  173.     assert( _xfe_app_shell != NULL );
  174.  
  175.     return _xfe_app_shell;
  176. }
  177. /*----------------------------------------------------------------------*/
  178. /* extern */ void
  179. XfeAppMainLoop(void)
  180. {
  181.     assert( _xfe_app_context != NULL );
  182.  
  183.     XtRealizeWidget(_xfe_app_shell);
  184.  
  185.     XtAppMainLoop(_xfe_app_context);
  186. }
  187. /*----------------------------------------------------------------------*/
  188. /* extern */ XtIntervalId
  189. XfeAppAddTimeOut(unsigned long            interval,
  190.                  XtTimerCallbackProc    proc,
  191.                  XtPointer                client_data)
  192. {
  193.     return XtAppAddTimeOut(XfeAppContext(),interval,proc,client_data);
  194. }
  195. /*----------------------------------------------------------------------*/
  196.