UNIXworkcode

1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * 3 * ***** BEGIN LICENSE BLOCK ***** 4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 5 * 6 * The contents of this file are subject to the Mozilla Public License Version 7 * 1.1 (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * http://www.mozilla.org/MPL/ 10 * 11 * Software distributed under the License is distributed on an "AS IS" basis, 12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 * for the specific language governing rights and limitations under the 14 * License. 15 * 16 * The Original Code is the Microline Widget Library, originally made available under the NPL by Neuron Data <http://www.neurondata.com>. 17 * 18 * The Initial Developer of the Original Code is 19 * Netscape Communications Corporation. 20 * Portions created by the Initial Developer are Copyright (C) 1998 21 * the Initial Developer. All Rights Reserved. 22 * 23 * Contributor(s): 24 * 25 * Alternatively, the contents of this file may be used under the terms of 26 * either the GNU General Public License Version 2 or later (the "GPL"), or 27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 28 * in which case the provisions of the GPL or the LGPL are applicable instead 29 * of those above. If you wish to allow use of your version of this file only 30 * under the terms of either the GPL or the LGPL, and not to allow others to 31 * use your version of this file under the terms of the MPL, indicate your 32 * decision by deleting the provisions above and replace them with the notice 33 * and other provisions required by the GPL or the LGPL. If you do not delete 34 * the provisions above, a recipient may use your version of this file under 35 * the terms of any one of the MPL, the GPL or the LGPL. 36 * 37 * In addition, as a special exception to the GNU GPL, the copyright holders 38 * give permission to link the code of this program with the Motif and Open 39 * Motif libraries (or with modified versions of these that use the same 40 * license), and distribute linked combinations including the two. You 41 * must obey the GNU General Public License in all respects for all of 42 * the code used other than linking with Motif/Open Motif. If you modify 43 * this file, you may extend this exception to your version of the file, 44 * but you are not obligated to do so. If you do not wish to do so, 45 * delete this exception statement from your version. 46 * 47 * ***** END LICENSE BLOCK ***** */ 48 49 50 #include <Xm/Xm.h> 51 #include <Xm/DrawnB.h> 52 #include <Xm/Form.h> 53 #include <Xm/Label.h> 54 #include <Xm/PushB.h> 55 #include <XmL/Folder.h> 56 57 void addTab(); 58 void removeTab(); 59 void activate(); 60 61 #define sphere_width 16 62 #define sphere_height 16 63 static unsigned char sphere_bits[] = { 64 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0x38, 0x3f, 65 0xb8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf0, 0x1f, 0xe0, 0x0f, 66 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 67 68 #define monitor_width 16 69 #define monitor_height 16 70 static unsigned char monitor_bits[] = { 71 0x00, 0x00, 0xf8, 0x3f, 0xf8, 0x3f, 0x18, 0x30, 0x58, 0x37, 0x18, 0x30, 72 0x58, 0x37, 0x18, 0x30, 0xf8, 0x3f, 0xf8, 0x3f, 0x80, 0x03, 0x80, 0x03, 73 0xf0, 0x1f, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00}; 74 75 Widget folder, label; 76 77 Pixmap monitorPixmap, spherePixmap; 78 79 main(argc, argv) 80 int argc; 81 char *argv[]; 82 { 83 XtAppContext app; 84 Widget shell, form, folderForm, addButton, removeButton; 85 Pixel black, grey; 86 87 shell = XtAppInitialize(&app, "Folder4", NULL, 0, 88 &argc, argv, NULL, NULL, 0); 89 90 XtVaSetValues(shell, 91 XmNallowShellResize, True, 92 NULL); 93 94 form = XtVaCreateManagedWidget("form", 95 xmFormWidgetClass, shell, 96 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 97 XmNmarginWidth, 8, 98 XmNmarginHeight, 8, 99 XmNhorizontalSpacing, 4, 100 XmNverticalSpacing, 4, 101 XmNshadowThickness, 0, 102 NULL); 103 104 /* Create Pixmaps with grey background (from form) */ 105 black = BlackPixelOfScreen(XtScreen(shell)); 106 XtVaGetValues(form, 107 XmNbackground, &grey, 108 NULL); 109 spherePixmap = XCreatePixmapFromBitmapData(XtDisplay(shell), 110 DefaultRootWindow(XtDisplay(shell)), 111 sphere_bits, sphere_width, sphere_height, 112 black, grey, 113 DefaultDepthOfScreen(XtScreen(shell))); 114 monitorPixmap = XCreatePixmapFromBitmapData(XtDisplay(shell), 115 DefaultRootWindow(XtDisplay(shell)), 116 monitor_bits, monitor_width, monitor_height, 117 black, grey, 118 DefaultDepthOfScreen(XtScreen(shell))); 119 120 removeButton = XtVaCreateManagedWidget("Remove Tab", 121 xmPushButtonWidgetClass, form, 122 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 123 XtVaTypedArg, XmNforeground, XmRString, "black", 6, 124 XmNrightAttachment, XmATTACH_FORM, 125 XmNbottomAttachment, XmATTACH_FORM, 126 XmNmarginWidth, 10, 127 NULL); 128 XtAddCallback(removeButton, XmNactivateCallback, removeTab, NULL); 129 130 addButton = XtVaCreateManagedWidget("Add Tab", 131 xmPushButtonWidgetClass, form, 132 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 133 XtVaTypedArg, XmNforeground, XmRString, "black", 6, 134 XmNrightAttachment, XmATTACH_WIDGET, 135 XmNrightWidget, removeButton, 136 XmNbottomAttachment, XmATTACH_FORM, 137 XmNmarginWidth, 20, 138 NULL); 139 XtAddCallback(addButton, XmNactivateCallback, addTab, NULL); 140 141 folder = XtVaCreateManagedWidget("folder", 142 xmlFolderWidgetClass, form, 143 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 144 XtVaTypedArg, XmNforeground, XmRString, "black", 6, 145 XmNtabsPerRow, 4, 146 XmNcornerStyle, XmCORNER_NONE, 147 XmNspacing, 1, 148 XmNtopAttachment, XmATTACH_FORM, 149 XmNbottomAttachment, XmATTACH_WIDGET, 150 XmNbottomWidget, removeButton, 151 XmNleftAttachment, XmATTACH_FORM, 152 XmNrightAttachment, XmATTACH_FORM, 153 XmNresizePolicy, XmRESIZE_DYNAMIC, 154 NULL); 155 XtAddCallback(folder, XmNactivateCallback, activate, NULL); 156 157 /* Add a Form to the Folder, this will appear in the page area */ 158 folderForm = XtVaCreateManagedWidget("form", 159 xmFormWidgetClass, folder, 160 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 161 NULL); 162 163 /* Add a Label as a child of the Form */ 164 label = XtVaCreateManagedWidget("Page Area", 165 xmLabelWidgetClass, folderForm, 166 XtVaTypedArg, XmNbackground, XmRString, "#C0C0C0", 8, 167 XtVaTypedArg, XmNforeground, XmRString, "black", 6, 168 XmNmarginWidth, 100, 169 XmNmarginHeight, 80, 170 XmNrecomputeSize, False, 171 XmNtopAttachment, XmATTACH_FORM, 172 XmNbottomAttachment, XmATTACH_FORM, 173 XmNleftAttachment, XmATTACH_FORM, 174 XmNrightAttachment, XmATTACH_FORM, 175 NULL); 176 177 XtRealizeWidget(shell); 178 XtAppMainLoop(app); 179 } 180 181 void addTab(w, clientData, callData) 182 Widget w; 183 XtPointer clientData; 184 XtPointer callData; 185 { 186 Widget tabButton, form; 187 int count; 188 char tabName[30]; 189 XmString str; 190 Pixmap pixmap; 191 192 XtVaGetValues(folder, 193 XmNtabCount, &count, 194 NULL); 195 196 /* Every other tab will have a sphere pixmap */ 197 if (count % 2) 198 pixmap = spherePixmap; 199 else 200 pixmap = monitorPixmap; 201 202 /* Add a tab (DrawnButton) to the Folder */ 203 sprintf(tabName, "Tab %d", count); 204 str = XmStringCreateSimple(tabName); 205 tabButton = XtVaCreateManagedWidget("tab", 206 xmDrawnButtonWidgetClass, folder, 207 XmNlabelString, str, 208 XmNmarginWidth, 8, 209 XmNtabPixmap, pixmap, 210 XmNtabInactivePixmap, pixmap, 211 NULL); 212 XmStringFree(str); 213 } 214 215 void removeTab(w, clientData, callData) 216 Widget w; 217 XtPointer clientData; 218 XtPointer callData; 219 { 220 int count; 221 WidgetList tabs; 222 223 XtVaGetValues(folder, 224 XmNtabCount, &count, 225 XmNtabWidgetList, &tabs, 226 NULL); 227 if (!count) 228 return; 229 XtDestroyWidget(tabs[count - 1]); 230 } 231 232 void activate(w, clientData, callData) 233 Widget w; 234 XtPointer clientData; 235 XtPointer callData; 236 { 237 XmLFolderCallbackStruct *cbs; 238 XmString str; 239 char buf[20]; 240 int pos; 241 242 /* Change the Label in the page area to reflect */ 243 /* the selected position */ 244 cbs = (XmLFolderCallbackStruct *)callData; 245 sprintf(buf, "Page %d", cbs->pos); 246 str = XmStringCreateSimple(buf); 247 XtVaSetValues(label, 248 XmNlabelString, str, 249 NULL); 250 } 251