home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / Microline3.0 / examples / folder4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.5 KB  |  229 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.  * The following source code is part of the Microline Widget Library.
  21.  * The Microline widget library is made available to Mozilla developers
  22.  * under the Netscape Public License (NPL) by Neuron Data.  To learn
  23.  * more about Neuron Data, please visit the Neuron Data Home Page at
  24.  * http://www.neurondata.com.
  25.  */
  26.  
  27.  
  28. #include <Xm/Xm.h>
  29. #include <Xm/DrawnB.h>
  30. #include <Xm/Form.h>
  31. #include <Xm/Label.h>
  32. #include <Xm/PushB.h>
  33. #include <XmL/Folder.h>
  34.  
  35. void addTab();
  36. void removeTab();
  37. void activate();
  38.  
  39. #define sphere_width 16
  40. #define sphere_height 16
  41. static unsigned char sphere_bits[] = {
  42.     0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0x38, 0x3f,
  43.     0xb8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf0, 0x1f, 0xe0, 0x0f,
  44.     0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  45.  
  46. #define monitor_width 16
  47. #define monitor_height 16
  48. static unsigned char monitor_bits[] = {
  49.     0x00, 0x00, 0xf8, 0x3f, 0xf8, 0x3f, 0x18, 0x30, 0x58, 0x37, 0x18, 0x30,
  50.     0x58, 0x37, 0x18, 0x30, 0xf8, 0x3f, 0xf8, 0x3f, 0x80, 0x03, 0x80, 0x03,
  51.     0xf0, 0x1f, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00};
  52.  
  53. Widget folder, label;
  54.  
  55. Pixmap monitorPixmap, spherePixmap;
  56.  
  57. main(argc, argv)
  58. int argc;
  59. char *argv[];
  60. {
  61.     XtAppContext app;
  62.     Widget shell, form, folderForm, addButton, removeButton;
  63.     Pixel black, grey;
  64.  
  65.     shell =  XtAppInitialize(&app, "Folder4", NULL, 0,
  66.         &argc, argv, NULL, NULL, 0);
  67.  
  68.     XtVaSetValues(shell,
  69.         XmNallowShellResize, True,
  70.         NULL);
  71.  
  72.     form = XtVaCreateManagedWidget("form",
  73.         xmFormWidgetClass, shell,
  74.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
  75.         XmNmarginWidth, 8,
  76.         XmNmarginHeight, 8,
  77.         XmNhorizontalSpacing, 4,
  78.         XmNverticalSpacing, 4,
  79.         XmNshadowThickness, 0,
  80.         NULL);
  81.  
  82.     /* Create Pixmaps with grey background (from form) */
  83.     black = BlackPixelOfScreen(XtScreen(shell));
  84.     XtVaGetValues(form,
  85.         XmNbackground, &grey,
  86.         NULL);
  87.     spherePixmap = XCreatePixmapFromBitmapData(XtDisplay(shell),
  88.         DefaultRootWindow(XtDisplay(shell)),
  89.         sphere_bits, sphere_width, sphere_height,
  90.         black, grey,
  91.         DefaultDepthOfScreen(XtScreen(shell)));
  92.     monitorPixmap = XCreatePixmapFromBitmapData(XtDisplay(shell),
  93.         DefaultRootWindow(XtDisplay(shell)),
  94.         monitor_bits, monitor_width, monitor_height,
  95.         black, grey,
  96.         DefaultDepthOfScreen(XtScreen(shell)));
  97.  
  98.     removeButton = XtVaCreateManagedWidget("Remove Tab",
  99.         xmPushButtonWidgetClass, form,
  100.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
  101.         XtVaTypedArg, XmNforeground, XmRString, "black", 6,
  102.         XmNrightAttachment, XmATTACH_FORM,
  103.         XmNbottomAttachment, XmATTACH_FORM,
  104.         XmNmarginWidth, 10,
  105.         NULL);
  106.     XtAddCallback(removeButton, XmNactivateCallback, removeTab, NULL);
  107.  
  108.     addButton = XtVaCreateManagedWidget("Add Tab",
  109.         xmPushButtonWidgetClass, form,
  110.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
  111.         XtVaTypedArg, XmNforeground, XmRString, "black", 6,
  112.         XmNrightAttachment, XmATTACH_WIDGET,
  113.         XmNrightWidget, removeButton,
  114.         XmNbottomAttachment, XmATTACH_FORM,
  115.         XmNmarginWidth, 20,
  116.         NULL);
  117.     XtAddCallback(addButton, XmNactivateCallback, addTab, NULL);
  118.  
  119.     folder = XtVaCreateManagedWidget("folder",
  120.         xmlFolderWidgetClass, form,
  121.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
  122.         XtVaTypedArg, XmNforeground, XmRString, "black", 6,
  123.         XmNtabsPerRow, 4,
  124.         XmNcornerStyle, XmCORNER_NONE,
  125.         XmNspacing, 1,
  126.         XmNtopAttachment, XmATTACH_FORM,
  127.         XmNbottomAttachment, XmATTACH_WIDGET,
  128.         XmNbottomWidget, removeButton,
  129.         XmNleftAttachment, XmATTACH_FORM,
  130.         XmNrightAttachment, XmATTACH_FORM,
  131.         XmNresizePolicy, XmRESIZE_DYNAMIC,
  132.         NULL);
  133.     XtAddCallback(folder, XmNactivateCallback, activate, NULL);
  134.  
  135.     /* Add a Form to the Folder, this will appear in the page area */
  136.     folderForm = XtVaCreateManagedWidget("form",
  137.         xmFormWidgetClass, folder,
  138.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
  139.         NULL);
  140.  
  141.     /* Add a Label as a child of the Form */
  142.     label = XtVaCreateManagedWidget("Page Area",
  143.         xmLabelWidgetClass, folderForm,
  144.         XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8,
  145.         XtVaTypedArg, XmNforeground, XmRString, "black", 6,
  146.         XmNmarginWidth, 100,
  147.         XmNmarginHeight, 80,
  148.         XmNrecomputeSize, False,
  149.         XmNtopAttachment, XmATTACH_FORM,
  150.         XmNbottomAttachment, XmATTACH_FORM,
  151.         XmNleftAttachment, XmATTACH_FORM,
  152.         XmNrightAttachment, XmATTACH_FORM,
  153.         NULL);
  154.  
  155.     XtRealizeWidget(shell);
  156.     XtAppMainLoop(app);
  157. }
  158.  
  159. void addTab(w, clientData, callData)
  160. Widget w;
  161. XtPointer clientData;
  162. XtPointer callData;
  163. {
  164.     Widget tabButton, form;
  165.     int count;
  166.     char tabName[30];
  167.     XmString str;
  168.     Pixmap pixmap;
  169.  
  170.     XtVaGetValues(folder,
  171.         XmNtabCount, &count,
  172.         NULL);
  173.  
  174.     /* Every other tab will have a sphere pixmap */
  175.     if (count % 2)
  176.         pixmap = spherePixmap;
  177.     else
  178.         pixmap = monitorPixmap;
  179.  
  180.     /* Add a tab (DrawnButton) to the Folder */
  181.     sprintf(tabName, "Tab %d", count);
  182.     str = XmStringCreateSimple(tabName);
  183.     tabButton = XtVaCreateManagedWidget("tab",
  184.         xmDrawnButtonWidgetClass, folder,
  185.         XmNlabelString, str,
  186.         XmNmarginWidth, 8,
  187.         XmNtabPixmap, pixmap,
  188.         XmNtabInactivePixmap, pixmap,
  189.         NULL);
  190.     XmStringFree(str);
  191. }
  192.  
  193. void removeTab(w, clientData, callData)
  194. Widget w;
  195. XtPointer clientData;
  196. XtPointer callData;
  197. {
  198.     int count;
  199.     WidgetList tabs;
  200.  
  201.     XtVaGetValues(folder,
  202.         XmNtabCount, &count,
  203.         XmNtabWidgetList, &tabs,
  204.         NULL);
  205.     if (!count)
  206.         return;
  207.     XtDestroyWidget(tabs[count - 1]);
  208. }
  209.  
  210. void activate(w, clientData, callData)
  211. Widget w;
  212. XtPointer clientData;
  213. XtPointer callData;
  214. {
  215.     XmLFolderCallbackStruct *cbs;
  216.     XmString str;
  217.     char buf[20];
  218.     int pos;
  219.  
  220.     /* Change the Label in the page area to reflect */
  221.     /* the selected position */
  222.     cbs = (XmLFolderCallbackStruct *)callData;
  223.     sprintf(buf, "Page %d", cbs->pos);
  224.     str = XmStringCreateSimple(buf);
  225.     XtVaSetValues(label,
  226.         XmNlabelString, str,
  227.         NULL);
  228. }
  229.