home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / tests / TaskBarTestOne.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.3 KB  |  255 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:        TaskBarTestOne.c                                        */
  21. /* Description:    Test for XfeTaskBar widget.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeTest.h>
  28.  
  29.  
  30. #include <Xm/MwmUtil.h>
  31.  
  32.  
  33. #include <X11/Shell.h>
  34.  
  35. #include <Xfe/XfeP.h>
  36.  
  37.  
  38. static String names[] =
  39. {
  40.     "One",
  41.     "Two",
  42.     "Three",
  43.     "Four",
  44.     "Five",
  45.     "Six"
  46. };
  47.  
  48. static String icons_large[] =
  49. {
  50.     "icons/bar_web.xpm",
  51.     "icons/bar_news.xpm",
  52.     "icons/bar_mail.xpm",
  53.     "icons/bar_web.xpm",
  54.     "icons/bar_news.xpm",
  55.     "icons/bar_mail.xpm",
  56. };
  57.  
  58. #define LOGO_PIXMAP        "icons/logo.xpm"
  59. #define DRAG_PIXMAP        "icons/drag_tile.xpm"
  60. #define UNDOCK_PIXMAP    "icons/undock.xpm"
  61.  
  62. static void        undock_callback            (Widget,XtPointer,XtPointer);
  63. static void        dock_callback            (Widget,XtPointer,XtPointer);
  64. static void        tool_active_callback    (Widget,XtPointer,XtPointer);
  65.  
  66. static Widget    create_docked_task_bar    (String,Widget);
  67. static Widget    create_foating_task_bar    (String,Widget);
  68.  
  69. static Widget    _floating_tb = NULL;
  70. static Widget    _floating_shell = NULL;
  71. static Widget    _docked_tb = NULL;
  72.  
  73. /*----------------------------------------------------------------------*/
  74. int
  75. main(int argc,char *argv[])
  76. {
  77.     Widget    form;
  78.     Widget    frame;
  79.  
  80.     XfeAppCreateSimple("TaskBarTestOne",&argc,argv,"MainFrame",&frame,&form);
  81.  
  82.     _docked_tb = create_docked_task_bar("DockedTaskBar",form);
  83.  
  84.     _floating_tb = create_foating_task_bar("FloatingShell",_docked_tb);
  85.  
  86.     XtAddCallback(_docked_tb,XmNactionCallback,undock_callback,NULL);
  87.  
  88.  
  89. #if 0
  90.     XtAddCallback(_floating_tb,XmNactionCallback,dock_callback,NULL);
  91. #else
  92.     XtAddCallback(_floating_tb,XmNcloseCallback,dock_callback,NULL);
  93. #endif
  94.  
  95.     XtManageChild(_docked_tb);
  96.  
  97.     XtPopup(frame,XtGrabNone);
  98.  
  99.     XfeAppMainLoop();
  100.  
  101.     return 0;
  102. }
  103. /*----------------------------------------------------------------------*/
  104. static Widget
  105. create_docked_task_bar(String name,Widget parent)
  106. {
  107.     Widget        tb;
  108.     Cardinal    i;
  109.     Pixmap        action_pixmap;
  110.  
  111.     tb = XtVaCreateWidget(name,
  112.                           xfeTaskBarWidgetClass,
  113.                           parent,
  114.                           XmNshowActionButton, True,
  115.                           NULL);
  116.  
  117.     action_pixmap = XfeGetPixmapFromFile(tb,UNDOCK_PIXMAP);
  118.  
  119.     XtVaSetValues(tb,
  120.                   XmNactionPixmap,    action_pixmap,
  121.                   NULL);
  122.  
  123.     for (i = 0; i < XtNumber(names); i++)
  124.     {
  125.         Widget w;
  126.         Pixmap p_normal;
  127.         Pixmap p_raised;
  128.         Pixmap p_armed;
  129.         
  130.         w = XtVaCreateManagedWidget(names[i],
  131.                                     xfeButtonWidgetClass,
  132.                                     tb,
  133.                                     NULL);
  134.     
  135.         p_normal = XfeGetPixmapFromFile(w,icons_large[i]);
  136.         p_raised = XfeGetPixmapFromFile(w,icons_large[i]);
  137.         p_armed  = XfeGetPixmapFromFile(w,icons_large[i]);
  138.         
  139.         XtVaSetValues(w,
  140.                       XmNpixmap,        p_normal,
  141.                       XmNraisedPixmap,    p_raised,
  142.                       XmNarmedPixmap,    p_armed,
  143.                       NULL);
  144.  
  145.         XtAddCallback(w,XmNactivateCallback,tool_active_callback,NULL);
  146.     }
  147.  
  148.     return tb;
  149. }
  150. /*----------------------------------------------------------------------*/
  151. static Widget
  152. create_foating_task_bar(String name,Widget parent)
  153. {
  154.     Widget        tb;
  155.     Pixmap        action_pixmap;
  156.     Pixmap        drag_pixmap;
  157.  
  158.     int            mask;
  159.     int            mode;
  160.     int            func;
  161.  
  162.     mask = MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MENU;
  163.     mode = MWM_INPUT_PRIMARY_APPLICATION_MODAL;
  164.     func = MWM_FUNC_CLOSE | MWM_FUNC_MOVE;
  165.  
  166. /*    mask = 0;*/
  167.  
  168.     _floating_shell = 
  169.         XtVaCreatePopupShell(name,
  170.                              xmDialogShellWidgetClass,
  171.                              XfeAncestorFindTopLevelShell(parent),
  172.                              XmNmwmDecorations,            mask,
  173.                              XmNmwmInputMode,            mode,
  174.                              XmNmwmFunctions,            func,
  175.                              XmNallowShellResize,        True,
  176.                              XmNdeleteResponse,            XmDO_NOTHING,
  177.                              NULL);
  178.  
  179.     tb = create_docked_task_bar("FloatingTaskBar",_floating_shell);
  180.  
  181.     XtVaSetValues(tb,XmNshowActionButton,False,NULL);
  182.  
  183.     action_pixmap = XfeGetPixmapFromFile(tb,LOGO_PIXMAP);
  184.     drag_pixmap = XfeGetPixmapFromFile(tb,DRAG_PIXMAP);
  185.  
  186. #if 0    
  187.     XtVaSetValues(tb,
  188.                   XmNactionPixmap,    action_pixmap,
  189.                   XmNdragPixmap,    drag_pixmap,
  190.                   NULL);
  191. #endif
  192.  
  193.     return tb;
  194. }
  195. /*----------------------------------------------------------------------*/
  196. static void
  197. tool_active_callback(Widget w,XtPointer client_data,XtPointer call_data)
  198. {
  199.     /* I want more siblings */
  200.     XtVaCreateManagedWidget("New Task",
  201.                             xfeButtonWidgetClass,
  202.                             XtParent(w),
  203.                             NULL);
  204. }
  205. /*----------------------------------------------------------------------*/
  206. static void
  207. undock_callback(Widget w,XtPointer client_data,XtPointer call_data)
  208. {
  209.     static first_map = True;
  210.  
  211.     XtUnmanageChild(_docked_tb);
  212.  
  213. #if 0
  214.     XtResizeWidget(_floating_shell,
  215.                    _XfeWidth(_floating_tb),
  216.                    _XfeHeight(_floating_tb),
  217.                    0);
  218. #endif
  219.  
  220.     if (first_map)
  221.     {
  222.         Widget        top_shell = XfeAncestorFindTopLevelShell(_docked_tb);
  223.  
  224.         Position    x = 
  225.             XfeRootX(top_shell) + 
  226.             XfeWidth(top_shell) - 
  227.             XfeWidth(_floating_tb) - 
  228.             0;
  229.  
  230.         Position    y = 
  231.             XfeRootY(top_shell) + 
  232.             XfeHeight(top_shell) - 
  233.             XfeHeight(_floating_tb) - 
  234.             0;
  235.  
  236.         XtVaSetValues(_floating_shell,
  237.                       XmNx,        x,
  238.                       XmNy,        y,
  239.                       NULL);
  240.  
  241.         first_map = False;
  242.     }
  243.  
  244.     XtManageChild(_floating_tb);
  245. }
  246. /*----------------------------------------------------------------------*/
  247. static void
  248. dock_callback(Widget w,XtPointer client_data,XtPointer call_data)
  249. {
  250.     XtManageChild(_docked_tb);
  251.  
  252.     XtUnmanageChild(_floating_tb);
  253. }
  254. /*----------------------------------------------------------------------*/
  255.