~ubuntu-branches/ubuntu/precise/pcb/precise

« back to all changes in this revision

Viewing changes to src/control.c

  • Committer: Bazaar Package Importer
  • Author(s): Hamish Moffatt
  • Date: 2005-02-20 13:14:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050220131400-pfz66g5vhx0azl8f
Tags: 1.99j+20050127-2
* Improved package description: (closes: #295405)
* Fixed dependency: tk84 -> tk8.4 (closes: #295404)
* Updated README.debian (closes: #269578)
* Applied patch to src/djopt.c to allow compilation with gcc-4.0
  (closes: #294319), thanks to Andreas Jochens for the patch.
* Prevent example files from being compressed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: control.c,v 1.6 2005/01/13 22:13:28 danmc Exp $ */
 
2
 
1
3
/*
2
4
 *                            COPYRIGHT
3
5
 *
24
26
 *
25
27
 */
26
28
 
27
 
static  char    *rcsid = "$Id: control.c,v 1.1 1998/02/19 18:06:34 sync Exp $";
28
 
 
29
29
/* control panel
30
30
 */
31
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
#include "config.h"
 
34
#endif
 
35
 
32
36
#include <stdio.h>
33
37
#include <stdlib.h>
34
38
 
50
54
#include <X11/Xaw/Label.h>
51
55
#include <X11/Xaw/Toggle.h>
52
56
 
 
57
#ifdef HAVE_LIBDMALLOC
 
58
#include <dmalloc.h>
 
59
#endif
 
60
 
 
61
RCSID("$Id: control.c,v 1.6 2005/01/13 22:13:28 danmc Exp $");
 
62
 
53
63
/* ---------------------------------------------------------------------------
54
64
 * include bitmap data
55
65
 */
63
73
/* ---------------------------------------------------------------------------
64
74
 * some local types
65
75
 */
66
 
typedef struct                                  /* description for a single mode button */
 
76
typedef struct                  /* description for a single mode button */
67
77
{
68
 
        char                    *Name,          /* the widgets name and label */
69
 
                                        *Label;
70
 
        int                             Mode;           /* mode ID */
71
 
        char                    *Bitmap;        /* background bitmap data */
72
 
        unsigned int    Width,          /* bitmap size */
73
 
                                        Height;
74
 
        Widget                  W;
75
 
} ModeButtonType, *ModeButtonTypePtr;
 
78
  char *Name,                   /* the widgets name and label */
 
79
   *Label;
 
80
  int Mode;                     /* mode ID */
 
81
  unsigned char *Bitmap;                        /* background bitmap data */
 
82
  unsigned int Width,           /* bitmap size */
 
83
    Height;
 
84
  Widget W;
 
85
}
 
86
ModeButtonType, *ModeButtonTypePtr;
76
87
 
77
88
/* ---------------------------------------------------------------------------
78
89
 * some local prototypes
79
90
 */
80
 
static  Widget          AddLabel(String, Widget, Widget, Widget);
81
 
static  void            AddDrawingLayerSelection(Widget);
82
 
static  void            AddOnOffSelection(Widget);
83
 
static  void            UpdateDrawingLayerSelection(void);
84
 
static  void            UpdateOnOffSelection(void);
85
 
static  Cardinal        GetGroupOfLayer(Cardinal);
86
 
static  void            PushOnTopOfLayerStack(int);
87
 
static  void            CBPOPUP_SetDrawingLayer(Widget, XtPointer, XtPointer);
88
 
static  void            CB_SetOnOff(Widget, XtPointer, XtPointer);
89
 
static  void            CB_SetDrawingLayer(Widget, XtPointer, XtPointer);
90
 
static  void            CB_SetMode(Widget, XtPointer, XtPointer);
 
91
static Widget AddLabel (String, Widget, Widget, Widget);
 
92
static void AddDrawingLayerSelection (Widget);
 
93
static void AddOnOffSelection (Widget);
 
94
static void UpdateDrawingLayerSelection (void);
 
95
static void UpdateOnOffSelection (void);
 
96
static void PushOnTopOfLayerStack (int);
 
97
static void CBPOPUP_SetDrawingLayer (Widget, XtPointer, XtPointer);
 
98
static void CB_SetOnOff (Widget, XtPointer, XtPointer);
 
99
static void CB_SetDrawingLayer (Widget, XtPointer, XtPointer);
 
100
static void CB_SetMode (Widget, XtPointer, XtPointer);
91
101
 
92
102
/* ---------------------------------------------------------------------------
93
103
 * some local identifiers
94
104
 */
95
 
static  Widget  OnOffWidgets[MAX_LAYER+6];      /* widgets for on/off selection */
96
 
 
97
 
static  PopupEntryType  DrawingLayerMenuEntries[MAX_LAYER+2];
98
 
static  PopupMenuType   DrawingLayerMenu =
99
 
        { "drawingLayer", NULL, DrawingLayerMenuEntries,
100
 
                CBPOPUP_SetDrawingLayer, NULL, NULL };
101
 
static  MenuButtonType  DrawingLayerMenuButton =
102
 
        { "drawingLayer", "DrawingLayer", &DrawingLayerMenu, NULL};
103
 
 
104
 
static  ModeButtonType  ModeButtons[] = {
105
 
        { "viaIcon", "via", VIA_MODE, ViaModeIcon_bits,
106
 
                ViaModeIcon_width, ViaModeIcon_height, NULL },
107
 
        { "lineIcon", "line", LINE_MODE, LineModeIcon_bits,
108
 
                LineModeIcon_width, LineModeIcon_height, NULL },
109
 
        { "arcIcon", "arc", ARC_MODE, ArcModeIcon_bits,
110
 
                ArcModeIcon_width, ArcModeIcon_height, NULL},
111
 
        { "textIcon", "text", TEXT_MODE, TextModeIcon_bits,
112
 
                TextModeIcon_width, TextModeIcon_height, NULL },
113
 
        { "rectangleIcon", "rectangle", RECTANGLE_MODE, RectModeIcon_bits,
114
 
                RectModeIcon_width, RectModeIcon_height, NULL },
115
 
        { "polygonIcon", "polygon", POLYGON_MODE, PolygonModeIcon_bits,
116
 
                PolygonModeIcon_width, PolygonModeIcon_height, NULL },
117
 
        { "bufferIcon", "buffer", PASTEBUFFER_MODE, BufferModeIcon_bits,
118
 
                BufferModeIcon_width, BufferModeIcon_height, NULL },
119
 
        { "removeIcon", "remove", REMOVE_MODE, RemoveModeIcon_bits,
120
 
                RemoveModeIcon_width, RemoveModeIcon_height, NULL },
121
 
        { "rotateIcon", "rotate", ROTATE_MODE, RotateModeIcon_bits,
122
 
                RotateModeIcon_width, RotateModeIcon_height, NULL },
123
 
        { "insertPointIcon", "insertPoint", INSERTPOINT_MODE,
124
 
                InsertPointModeIcon_bits, InsertPointModeIcon_width,
125
 
                InsertPointModeIcon_height, NULL },
126
 
        { "thermalIcon", "thermal", THERMAL_MODE, ThermalModeIcon_bits,
127
 
                ThermalModeIcon_width, ThermalModeIcon_height, NULL},
128
 
        { "selectIcon", "select", ARROW_MODE, SelModeIcon_bits,
129
 
                SelModeIcon_width, SelModeIcon_height, NULL}};
 
105
static Widget OnOffWidgets[MAX_LAYER + 6];      /* widgets for on/off selection */
 
106
 
 
107
static PopupEntryType DrawingLayerMenuEntries[MAX_LAYER + 3];
 
108
static PopupMenuType DrawingLayerMenu =
 
109
  { "drawingLayer", NULL, DrawingLayerMenuEntries,
 
110
  CBPOPUP_SetDrawingLayer, NULL, NULL
 
111
};
 
112
static MenuButtonType DrawingLayerMenuButton =
 
113
  { "drawingLayer", "DrawingLayer", &DrawingLayerMenu, NULL };
 
114
 
 
115
static ModeButtonType ModeButtons[] = {
 
116
  {"viaIcon", "via", VIA_MODE, ViaModeIcon_bits,
 
117
   ViaModeIcon_width, ViaModeIcon_height, NULL},
 
118
  {"lineIcon", "line", LINE_MODE, LineModeIcon_bits,
 
119
   LineModeIcon_width, LineModeIcon_height, NULL},
 
120
  {"arcIcon", "arc", ARC_MODE, ArcModeIcon_bits,
 
121
   ArcModeIcon_width, ArcModeIcon_height, NULL},
 
122
  {"textIcon", "text", TEXT_MODE, TextModeIcon_bits,
 
123
   TextModeIcon_width, TextModeIcon_height, NULL},
 
124
  {"rectangleIcon", "rectangle", RECTANGLE_MODE, RectModeIcon_bits,
 
125
   RectModeIcon_width, RectModeIcon_height, NULL},
 
126
  {"polygonIcon", "polygon", POLYGON_MODE, PolygonModeIcon_bits,
 
127
   PolygonModeIcon_width, PolygonModeIcon_height, NULL},
 
128
  {"bufferIcon", "buffer", PASTEBUFFER_MODE, BufferModeIcon_bits,
 
129
   BufferModeIcon_width, BufferModeIcon_height, NULL},
 
130
  {"removeIcon", "remove", REMOVE_MODE, RemoveModeIcon_bits,
 
131
   RemoveModeIcon_width, RemoveModeIcon_height, NULL},
 
132
  {"rotateIcon", "rotate", ROTATE_MODE, RotateModeIcon_bits,
 
133
   RotateModeIcon_width, RotateModeIcon_height, NULL},
 
134
  {"insertPointIcon", "insertPoint", INSERTPOINT_MODE,
 
135
   InsertPointModeIcon_bits, InsertPointModeIcon_width,
 
136
   InsertPointModeIcon_height, NULL},
 
137
  {"thermalIcon", "thermal", THERMAL_MODE, ThermalModeIcon_bits,
 
138
   ThermalModeIcon_width, ThermalModeIcon_height, NULL},
 
139
  {"selectIcon", "select", ARROW_MODE, SelModeIcon_bits,
 
140
   SelModeIcon_width, SelModeIcon_height, NULL},
 
141
  {"panIcon", "pan", PAN_MODE, PanModeIcon_bits,
 
142
   PanModeIcon_width, PanModeIcon_height, NULL},
 
143
  {"lockIcon", "lock", LOCK_MODE, LockModeIcon_bits,
 
144
   LockModeIcon_width, LockModeIcon_height, NULL}
 
145
};
130
146
 
131
147
/* ---------------------------------------------------------------------------
132
148
 * adds a label without border, surrounded by additional space
133
149
 * at the specified position
134
150
 */
135
 
static Widget AddLabel(String Label, Widget Parent, Widget Top, Widget Left)
 
151
static Widget
 
152
AddLabel (String Label, Widget Parent, Widget Top, Widget Left)
136
153
{
137
 
        Widget          label;
138
 
        Dimension       height;
 
154
  Widget label;
 
155
  Dimension height;
139
156
 
140
 
        label = XtVaCreateManagedWidget("label", labelWidgetClass,
141
 
                Parent,
142
 
                XtNlabel, Label,
143
 
                XtNfromHoriz, Left,
144
 
                XtNfromVert, Top,
145
 
                XtNjustify, XtJustifyCenter,
146
 
                LAYOUT_TOP,
147
 
                NULL);
148
 
        XtVaGetValues(label, XtNheight, &height, NULL);
149
 
        XtVaSetValues(label, XtNheight, 3*height/2, NULL);
150
 
        return(label);
 
157
  label = XtVaCreateManagedWidget ("label", labelWidgetClass,
 
158
                                   Parent,
 
159
                                   XtNlabel, Label,
 
160
                                   XtNfromHoriz, Left,
 
161
                                   XtNfromVert, Top,
 
162
                                   XtNjustify, XtJustifyCenter,
 
163
                                   LAYOUT_TOP, NULL);
 
164
  XtVaGetValues (label, XtNheight, &height, NULL);
 
165
  XtVaSetValues (label, XtNheight, 3 * height / 2, NULL);
 
166
  return (label);
151
167
}
152
168
 
153
169
/* ---------------------------------------------------------------------------
154
170
 * create drawing-layer selection menu
155
171
 */
156
 
static void AddDrawingLayerSelection(Widget Parent)
 
172
static void
 
173
AddDrawingLayerSelection (Widget Parent)
157
174
{
158
 
        static  char    name[MAX_LAYER + 1][20];
159
 
                        int             i;
160
 
                        Widget  label;
161
 
                        Pixel   background;
162
 
 
163
 
                /* fill struct and initialize menu button */
164
 
        for (i = 0; i < MAX_LAYER + 1; i++)
165
 
        {
166
 
                        /* the widgets name is used for the 'CheckEntry()' funtion
167
 
                         * and must be declared static therefore
168
 
                         */
169
 
                sprintf(name[i], "layer%-i", i+1);
170
 
                DrawingLayerMenuEntries[i].Name = name[i];
171
 
                DrawingLayerMenuEntries[i].Label = name[i];
172
 
                DrawingLayerMenuEntries[i].Callback = CB_SetDrawingLayer;
173
 
                DrawingLayerMenuEntries[i].ClientData = (XtPointer) i;
174
 
        }
175
 
        
176
 
 
177
 
                /* init routine exits on NULL pointer */
178
 
        DrawingLayerMenuEntries[i].Name = NULL;
179
 
        DrawingLayerMenuEntries[i].Label = NULL;
180
 
        label = AddLabel("active", Parent, NULL, NULL);
181
 
        InitMenuButton(Parent, &DrawingLayerMenuButton, label, NULL);
182
 
        XtVaGetValues(DrawingLayerMenuButton.W,
183
 
                XtNbackground, &background,
184
 
                NULL);
185
 
        XtVaSetValues(DrawingLayerMenuButton.W,
186
 
                XtNforeground, background,
187
 
                NULL);
 
175
  static char name[MAX_LAYER + 2][20];
 
176
  long int i;
 
177
  Widget label;
 
178
  Pixel background;
 
179
 
 
180
  /* fill struct and initialize menu button */
 
181
  for (i = 0; i < MAX_LAYER + 2; i++)
 
182
    {
 
183
      /* the widgets name is used for the 'CheckEntry()' funtion
 
184
       * and must be declared static therefore
 
185
       */
 
186
      sprintf (name[i], "layer%-li", i + 1);
 
187
      DrawingLayerMenuEntries[i].Name = name[i];
 
188
      DrawingLayerMenuEntries[i].Label = name[i];
 
189
      DrawingLayerMenuEntries[i].Callback = CB_SetDrawingLayer;
 
190
      DrawingLayerMenuEntries[i].ClientData = (XtPointer) i;
 
191
    }
 
192
 
 
193
  /* init routine exits on NULL pointer */
 
194
  DrawingLayerMenuEntries[i].Name = NULL;
 
195
  DrawingLayerMenuEntries[i].Label = NULL;
 
196
  label = AddLabel ("active", Parent, NULL, NULL);
 
197
  InitMenuButton (Parent, &DrawingLayerMenuButton, label, NULL);
 
198
  XtVaGetValues (DrawingLayerMenuButton.W, XtNbackground, &background, NULL);
 
199
  XtVaSetValues (DrawingLayerMenuButton.W, XtNforeground, background, NULL);
188
200
}
189
201
 
190
202
/* ---------------------------------------------------------------------------
191
203
 * adds the layer On/Off selection buttons to our dialog (downwards)
192
204
 * the label for the layer buttons are set by UpdateOnOffSelection()
193
205
 */
194
 
static void AddOnOffSelection(Widget Parent)
 
206
static void
 
207
AddOnOffSelection (Widget Parent)
195
208
{
196
 
        static  char    name[MAX_LAYER+5][20];
197
 
                        Widget  last;
198
 
                        int             i;
199
 
                        char    *text;
200
 
                        Pixel   color;
201
 
 
202
 
                /* insert a label at the top */
203
 
        last = AddLabel("on/off", Parent, NULL, NULL);
204
 
 
205
 
        for (i = 0; i < MAX_LAYER+5; i++)
 
209
  static char name[MAX_LAYER + 5][20];
 
210
  Widget last;
 
211
  long int i;
 
212
  char *text;
 
213
  Pixel color;
 
214
 
 
215
  /* insert a label at the top */
 
216
  last = AddLabel ("on/off", Parent, NULL, NULL);
 
217
 
 
218
  for (i = 0; i < MAX_LAYER + 5; i++)
 
219
    {
 
220
      switch (i)
206
221
        {
207
 
                switch(i)
208
 
                {
209
 
                        case MAX_LAYER:                 /* settings for elements */
210
 
                                color = PCB->ElementColor;
211
 
                                text = "silk";
212
 
                                strcpy(name[i], "elements");
213
 
                                break;
214
 
 
215
 
                        case MAX_LAYER+1:               /* settings for pins */
216
 
                                color = PCB->PinColor;
217
 
                                text = "pins/pads";
218
 
                                strcpy(name[i], "pins");
219
 
                                break;
220
 
 
221
 
                        case MAX_LAYER+2:               /* settings for vias */
222
 
                                color = PCB->ViaColor;
223
 
                                text = "vias";
224
 
                                strcpy(name[i], "vias");
225
 
                                break;
226
 
 
227
 
                        case MAX_LAYER+3:               /* settings for objects on opposite side */
228
 
                                color = PCB->InvisibleObjectsColor;
229
 
                                text = "far side";
230
 
                                strcpy(name[i], "invisible");
231
 
                                break;
232
 
 
233
 
                        case MAX_LAYER+4:               /* settings for rats */
234
 
                                color = PCB->RatColor;
235
 
                                text = "rat lines";
236
 
                                strcpy(name[i], "rats");
237
 
                                break;
238
 
 
239
 
 
240
 
                        default:                                /* layers */
241
 
                                color = PCB->Data->Layer[i].Color;
242
 
                                text = "";
243
 
                                sprintf(name[i], "layer%-i", i+1);
244
 
                                break;
245
 
                }
246
 
 
247
 
                        /* create widget and install callback function */
248
 
                OnOffWidgets[i] = XtVaCreateManagedWidget(name[i],toggleWidgetClass,
249
 
                        Parent,
250
 
                        XtNlabel, text,
251
 
                        XtNforeground, color,
252
 
                        XtNfromHoriz, NULL,
253
 
                        XtNfromVert, last,
254
 
                        LAYOUT_TOP,
255
 
                        NULL);
256
 
                last = OnOffWidgets[i];
257
 
                XtAddCallback(last, XtNcallback, CB_SetOnOff, (XtPointer) i);
 
222
        case MAX_LAYER: /* settings for elements */
 
223
          color = PCB->ElementColor;
 
224
          text = "silk";
 
225
          strcpy (name[i], "elements");
 
226
          break;
 
227
 
 
228
        case MAX_LAYER + 1:     /* settings for pins */
 
229
          color = PCB->PinColor;
 
230
          text = "pins/pads";
 
231
          strcpy (name[i], "pins");
 
232
          break;
 
233
 
 
234
        case MAX_LAYER + 2:     /* settings for vias */
 
235
          color = PCB->ViaColor;
 
236
          text = "vias";
 
237
          strcpy (name[i], "vias");
 
238
          break;
 
239
 
 
240
        case MAX_LAYER + 3:     /* settings for objects on opposite side */
 
241
          color = PCB->InvisibleObjectsColor;
 
242
          text = "far side";
 
243
          strcpy (name[i], "invisible");
 
244
          break;
 
245
 
 
246
        case MAX_LAYER + 4:     /* settings for rats */
 
247
          color = PCB->RatColor;
 
248
          text = "rat lines";
 
249
          strcpy (name[i], "rats");
 
250
          break;
 
251
 
 
252
 
 
253
        default:                /* layers */
 
254
          color = PCB->Data->Layer[i].Color;
 
255
          text = "";
 
256
          sprintf (name[i], "layer%-li", i + 1);
 
257
          break;
258
258
        }
 
259
 
 
260
      /* create widget and install callback function */
 
261
      OnOffWidgets[i] = XtVaCreateManagedWidget (name[i], toggleWidgetClass,
 
262
                                                 Parent,
 
263
                                                 XtNlabel, text,
 
264
                                                 XtNforeground, color,
 
265
                                                 XtNfromHoriz, NULL,
 
266
                                                 XtNfromVert, last,
 
267
                                                 LAYOUT_TOP, NULL);
 
268
      XtAddEventHandler (OnOffWidgets[i], EnterWindowMask, False,
 
269
                         CB_StopScroll, NULL);
 
270
      last = OnOffWidgets[i];
 
271
      XtAddCallback (last, XtNcallback, CB_SetOnOff, (XtPointer) i);
 
272
    }
259
273
}
260
274
 
261
275
/* ---------------------------------------------------------------------------
262
276
 * updates the drawing-layer selection menu
263
277
 */
264
 
static void UpdateDrawingLayerSelection(void)
 
278
static void
 
279
UpdateDrawingLayerSelection (void)
265
280
{
266
 
        int             i;
267
 
 
268
 
                /* PCB may have changed; we have to make sure that the
269
 
                 * labels are set correct
270
 
                 */
271
 
        for (i = 0; i < MAX_LAYER; i++)
272
 
                XtVaSetValues(DrawingLayerMenuEntries[i].W,
273
 
                        XtNlabel, UNKNOWN(PCB->Data->Layer[i].Name),
274
 
                        XtNforeground, PCB->Data->Layer[i].Color,
275
 
                        NULL);
276
 
        XtVaSetValues(DrawingLayerMenuEntries[i].W,
277
 
                XtNlabel, UNKNOWN(PCB->Data->Layer[i].Name),
278
 
                XtNforeground, PCB->ElementColor,
279
 
                NULL);
280
 
 
281
 
                /* set the label of the menu-button itself and reset a flag */
282
 
        XtVaSetValues(DrawingLayerMenuButton.W,
283
 
                XtNlabel, UNKNOWN(CURRENT->Name),
284
 
                XtNbackground, CURRENT->Color,
285
 
                NULL);
 
281
  int i;
 
282
 
 
283
  /* PCB may have changed; we have to make sure that the
 
284
   * labels are set correct
 
285
   */
 
286
  for (i = 0; i < MAX_LAYER; i++)
 
287
    XtVaSetValues (DrawingLayerMenuEntries[i].W,
 
288
                   XtNlabel, UNKNOWN (PCB->Data->Layer[i].Name),
 
289
                   XtNforeground, PCB->Data->Layer[i].Color, NULL);
 
290
  XtVaSetValues (DrawingLayerMenuEntries[i].W,
 
291
                 XtNlabel, UNKNOWN (PCB->Data->Layer[i].Name),
 
292
                 XtNforeground, PCB->ElementColor, NULL);
 
293
  i++;
 
294
  XtVaSetValues (DrawingLayerMenuEntries[i].W,
 
295
                 XtNlabel, "Netlist", XtNforeground, PCB->RatColor, NULL);
 
296
  /* set the label of the menu-button itself */
 
297
  if (PCB->RatDraw)
 
298
    XtVaSetValues (DrawingLayerMenuButton.W,
 
299
                   XtNlabel, "Netlist", XtNbackground, PCB->RatColor, NULL);
 
300
  else
 
301
    XtVaSetValues (DrawingLayerMenuButton.W,
 
302
                   XtNlabel, UNKNOWN (CURRENT->Name),
 
303
                   XtNbackground, CURRENT->Color, NULL);
286
304
}
287
305
 
288
306
/* ---------------------------------------------------------------------------
289
307
 * updates the layer On/Off selection buttons
290
308
 */
291
 
static void UpdateOnOffSelection(void)
 
309
static void
 
310
UpdateOnOffSelection (void)
292
311
{
293
 
        int             i;
294
 
 
295
 
                /* the buttons for elements, vias and pins never
296
 
                 * change their label, so we only check the layer buttons
297
 
                 */
298
 
        for (i = 0; i < MAX_LAYER; i++)
299
 
                XtVaSetValues(OnOffWidgets[i],
300
 
                        XtNlabel, UNKNOWN(PCB->Data->Layer[i].Name),
301
 
                        XtNstate, PCB->Data->Layer[i].On,
302
 
                        NULL);
303
 
 
304
 
                /* now set the state of elements, pins and vias */
305
 
        XtVaSetValues(OnOffWidgets[i++], XtNstate, PCB->ElementOn, NULL);
306
 
        XtVaSetValues(OnOffWidgets[i++], XtNstate, PCB->PinOn, NULL);
307
 
        XtVaSetValues(OnOffWidgets[i++], XtNstate, PCB->ViaOn, NULL);
308
 
        XtVaSetValues(OnOffWidgets[i++], XtNstate, PCB->InvisibleObjectsOn, NULL);
309
 
        XtVaSetValues(OnOffWidgets[i++], XtNstate, PCB->RatOn, NULL);
 
312
  int i;
 
313
 
 
314
  /* the buttons for elements, vias and pins never
 
315
   * change their label, so we only check the layer buttons
 
316
   */
 
317
  for (i = 0; i < MAX_LAYER; i++)
 
318
    XtVaSetValues (OnOffWidgets[i],
 
319
                   XtNlabel, UNKNOWN (PCB->Data->Layer[i].Name),
 
320
                   XtNstate, PCB->Data->Layer[i].On, NULL);
 
321
 
 
322
  /* now set the state of elements, pins and vias */
 
323
  XtVaSetValues (OnOffWidgets[i++], XtNstate, PCB->ElementOn, NULL);
 
324
  XtVaSetValues (OnOffWidgets[i++], XtNstate, PCB->PinOn, NULL);
 
325
  XtVaSetValues (OnOffWidgets[i++], XtNstate, PCB->ViaOn, NULL);
 
326
  XtVaSetValues (OnOffWidgets[i++], XtNstate, PCB->InvisibleObjectsOn, NULL);
 
327
  XtVaSetValues (OnOffWidgets[i++], XtNstate, PCB->RatOn, NULL);
310
328
}
311
329
 
312
330
/* ----------------------------------------------------------------------
313
331
 * lookup the group to which a layer belongs to
314
332
 * returns MAX_LAYER if no group is found
315
333
 */
316
 
static Cardinal GetGroupOfLayer(Cardinal Layer)
 
334
Cardinal
 
335
GetGroupOfLayer (Cardinal Layer)
317
336
{
318
 
        int     group,
319
 
                i;
 
337
  int group, i;
320
338
 
321
 
        if (Layer == MAX_LAYER)
322
 
                return(Layer);
323
 
        for (group = 0; group < MAX_LAYER; group++)
324
 
                for (i = 0; i < PCB->LayerGroups.Number[group]; i++)
325
 
                        if (PCB->LayerGroups.Entries[group][i] == Layer)
326
 
                                return(group);
327
 
        return(MAX_LAYER);
 
339
  if (Layer == MAX_LAYER)
 
340
    return (Layer);
 
341
  for (group = 0; group < MAX_LAYER; group++)
 
342
    for (i = 0; i < PCB->LayerGroups.Number[group]; i++)
 
343
      if (PCB->LayerGroups.Entries[group][i] == Layer)
 
344
        return (group);
 
345
  return (MAX_LAYER);
328
346
}
329
347
 
330
348
/* ----------------------------------------------------------------------
331
349
 * changes the visibility of all layers in a group
332
350
 * returns the number of changed layers
333
351
 */
334
 
int ChangeGroupVisibility(Cardinal Layer, Boolean On, Boolean ChangeStackOrder)
 
352
int
 
353
ChangeGroupVisibility (Cardinal Layer, Boolean On, Boolean ChangeStackOrder)
335
354
{
336
 
        int             group,
337
 
                        i,
338
 
                        changed = 1;    /* at least the current layer changes */
339
 
 
340
 
                /* special case of silk layer */
341
 
        if (Layer == MAX_LAYER)
342
 
        {
343
 
                PCB->ElementOn = On;
344
 
                PCB->SilkActive = On && ChangeStackOrder;
345
 
                SILKLAYER->On = On;
346
 
                BACKSILKLAYER->On = (On && PCB->InvisibleObjectsOn);
347
 
                UpdateOnOffSelection();
348
 
                return(0);
349
 
        }
350
 
        PCB->SilkActive = (On && ChangeStackOrder) ? False : PCB->SilkActive;
351
 
 
352
 
                /* decrement 'i' to keep stack in order of layergroup */
353
 
        if ((group = GetGroupOfLayer(Layer)) < MAX_LAYER)
354
 
                for (i = PCB->LayerGroups.Number[group]; i;) 
355
 
                {
356
 
                        int     layer = PCB->LayerGroups.Entries[group][--i];
357
 
 
358
 
                                /* dont count the passed member of the group */
359
 
                        if (layer != Layer && layer < MAX_LAYER)
360
 
                        {
361
 
                                PCB->Data->Layer[layer].On = On;
362
 
        
363
 
                                        /* push layer on top of stack if switched on */
364
 
                                if (On && ChangeStackOrder)
365
 
                                        PushOnTopOfLayerStack(layer);
366
 
                                changed++;
367
 
                        }
368
 
                }
369
 
 
370
 
                /* change at least the passed layer */
371
 
        PCB->Data->Layer[Layer].On = On;
372
 
        if (On && ChangeStackOrder)
373
 
                PushOnTopOfLayerStack(Layer);
374
 
 
375
 
                /* update control panel and exit */
376
 
        UpdateOnOffSelection();
377
 
        return(changed);
 
355
  int group, i, changed = 1;    /* at least the current layer changes */
 
356
 
 
357
  /* special case of rat (netlist layer) */
 
358
  if (Layer == MAX_LAYER + 1)
 
359
    {
 
360
      PCB->RatOn = On;
 
361
      PCB->RatDraw = On && ChangeStackOrder;
 
362
      if (PCB->RatDraw)
 
363
        SetMode (NO_MODE);
 
364
      UpdateOnOffSelection ();
 
365
      return (0);
 
366
    }
 
367
  else
 
368
    PCB->RatDraw = (On && ChangeStackOrder) ? False : PCB->RatDraw;
 
369
 
 
370
  /* special case of silk layer */
 
371
  if (Layer == MAX_LAYER)
 
372
    {
 
373
      PCB->ElementOn = On;
 
374
      PCB->SilkActive = On && ChangeStackOrder;
 
375
      PCB->Data->SILKLAYER.On = On;
 
376
      PCB->Data->BACKSILKLAYER.On = (On && PCB->InvisibleObjectsOn);
 
377
      UpdateOnOffSelection ();
 
378
      return (0);
 
379
    }
 
380
  PCB->SilkActive = (On && ChangeStackOrder) ? False : PCB->SilkActive;
 
381
 
 
382
  /* decrement 'i' to keep stack in order of layergroup */
 
383
  if ((group = GetGroupOfLayer (Layer)) < MAX_LAYER)
 
384
    for (i = PCB->LayerGroups.Number[group]; i;)
 
385
      {
 
386
        int layer = PCB->LayerGroups.Entries[group][--i];
 
387
 
 
388
        /* dont count the passed member of the group */
 
389
        if (layer != Layer && layer < MAX_LAYER)
 
390
          {
 
391
            PCB->Data->Layer[layer].On = On;
 
392
 
 
393
            /* push layer on top of stack if switched on */
 
394
            if (On && ChangeStackOrder)
 
395
              PushOnTopOfLayerStack (layer);
 
396
            changed++;
 
397
          }
 
398
      }
 
399
 
 
400
  /* change at least the passed layer */
 
401
  PCB->Data->Layer[Layer].On = On;
 
402
  if (On && ChangeStackOrder)
 
403
    PushOnTopOfLayerStack (Layer);
 
404
 
 
405
  /* update control panel and exit */
 
406
  UpdateOnOffSelection ();
 
407
  return (changed);
378
408
}
379
409
 
380
410
/* ---------------------------------------------------------------------------
381
411
 * move layer (number is passed in) to top of layerstack
382
412
 */
383
 
static void PushOnTopOfLayerStack(int NewTop)
 
413
static void
 
414
PushOnTopOfLayerStack (int NewTop)
384
415
{
385
 
        int             i;
386
 
 
387
 
                /* ignore COMPONENT_LAYER and SOLDER_LAYER */
388
 
        if (NewTop < MAX_LAYER)
389
 
        {
390
 
                        /* first find position of passed one */
391
 
                for (i = 0; i < MAX_LAYER; i++)
392
 
                        if (LayerStack[i] == NewTop)
393
 
                                break;
394
 
 
395
 
                        /* bring this element to the top of the stack */
396
 
                for(; i; i--)
397
 
                        LayerStack[i] = LayerStack[i-1];
398
 
                LayerStack[0] = NewTop;
399
 
        }
 
416
  int i;
 
417
 
 
418
  /* ignore COMPONENT_LAYER and SOLDER_LAYER */
 
419
  if (NewTop < MAX_LAYER)
 
420
    {
 
421
      /* first find position of passed one */
 
422
      for (i = 0; i < MAX_LAYER; i++)
 
423
        if (LayerStack[i] == NewTop)
 
424
          break;
 
425
 
 
426
      /* bring this element to the top of the stack */
 
427
      for (; i; i--)
 
428
        LayerStack[i] = LayerStack[i - 1];
 
429
      LayerStack[0] = NewTop;
 
430
    }
400
431
}
401
432
 
402
433
/* ---------------------------------------------------------------------------
403
434
 * callback routine, called when drawing-layer menu pops up
404
435
 */
405
 
static void CBPOPUP_SetDrawingLayer(Widget W,
406
 
        XtPointer ClientData, XtPointer CallData)
 
436
static void
 
437
CBPOPUP_SetDrawingLayer (Widget W, XtPointer ClientData, XtPointer CallData)
407
438
{
408
 
        char    name[10];
409
 
 
410
 
        RemoveCheckFromMenu(&DrawingLayerMenu);
411
 
        sprintf(name, "layer%-i", MIN(INDEXOFCURRENT, MAX_LAYER) + 1);
412
 
        CheckEntry(&DrawingLayerMenu, name);
 
439
  char name[10];
 
440
 
 
441
  RemoveCheckFromMenu (&DrawingLayerMenu);
 
442
  if (PCB->RatDraw)
 
443
    sprintf (name, "layer%-i", MAX_LAYER + 2);
 
444
  else
 
445
    sprintf (name, "layer%-i", MIN (INDEXOFCURRENT, MAX_LAYER) + 1);
 
446
  CheckEntry (&DrawingLayerMenu, name);
 
447
 
413
448
}
414
449
 
415
450
/* ---------------------------------------------------------------------------
418
453
 * this routine is either called from one of the toggle widgets or
419
454
 * from the output window by using accelerators
420
455
 */
421
 
static void CB_SetDrawingLayer(Widget W,
422
 
        XtPointer ClientData, XtPointer CallData)
 
456
static void
 
457
CB_SetDrawingLayer (Widget W, XtPointer ClientData, XtPointer CallData)
423
458
{
424
 
        LayerTypePtr lay;
 
459
  LayerTypePtr lay;
425
460
 
426
 
        ChangeGroupVisibility((int) ClientData, True, True);
427
 
        lay = CURRENT;
428
 
        XtVaSetValues(DrawingLayerMenuButton.W,
429
 
                XtNlabel, UNKNOWN(lay->Name),
430
 
                XtNbackground, lay->Color,
431
 
                NULL);
432
 
        UpdateAll();
 
461
  ChangeGroupVisibility ((long int) ClientData, True, True);
 
462
  lay = CURRENT;
 
463
  if (PCB->RatDraw)
 
464
    XtVaSetValues (DrawingLayerMenuButton.W,
 
465
                   XtNlabel, "Netlist", XtNbackground, PCB->RatColor, NULL);
 
466
  else
 
467
    XtVaSetValues (DrawingLayerMenuButton.W,
 
468
                   XtNlabel, UNKNOWN (lay->Name),
 
469
                   XtNbackground, lay->Color, NULL);
 
470
  UpdateAll ();
433
471
}
434
472
 
435
473
/* ---------------------------------------------------------------------------
436
474
 * callback routine, called when On/Off flag of layer is changed
437
475
 */
438
 
static void CB_SetOnOff(Widget W, XtPointer ClientData, XtPointer CallData)
 
476
static void
 
477
CB_SetOnOff (Widget W, XtPointer ClientData, XtPointer CallData)
439
478
{
440
 
        Boolean state, Redraw = False;
441
 
        int             layer = (int) ClientData;
442
 
 
443
 
                /* get new state of widget */
444
 
        XtVaGetValues(W, XtNstate, &state, NULL);
445
 
 
446
 
                /* set redraw flag if object exists */
447
 
        switch(layer)
448
 
        {
449
 
                case MAX_LAYER+1:               /* settings for pins */
450
 
                        PCB->PinOn = state;
451
 
                        Redraw |= (PCB->Data->ElementN != 0);
452
 
                        break;
453
 
 
454
 
                case MAX_LAYER+2:               /* settings for vias */
455
 
                        PCB->ViaOn = state;
456
 
                        Redraw |= (PCB->Data->ViaN != 0);
457
 
                        break;
458
 
 
459
 
                case MAX_LAYER+3:               /* settings for invisible objects */
460
 
                        PCB->InvisibleObjectsOn = state;
461
 
                        BACKSILKLAYER->On = (state && PCB->ElementOn);
462
 
                        Redraw = True;
463
 
                        break;
464
 
 
465
 
                case MAX_LAYER+4:               /* settings for rat lines */
466
 
                        PCB->RatOn = state;
467
 
                        Redraw |= (PCB->Data->RatN != 0);
468
 
                        break;
469
 
 
470
 
                default:
471
 
                {
472
 
                        int             i, group;
473
 
 
474
 
                                /* check if active layer is in the group;
475
 
                                 * if YES, make a different one active if possible
476
 
                                 */
477
 
                        if ((group = GetGroupOfLayer(layer)) ==
478
 
                                GetGroupOfLayer(MIN(MAX_LAYER, INDEXOFCURRENT)))
479
 
                        {
480
 
                                /* find next visible layer and make it
481
 
                                 * active so this one can be turned off
482
 
                                 */
483
 
                                for (i = (layer + 1) % (MAX_LAYER + 1);
484
 
                                     i != layer; i = (i + 1) % (MAX_LAYER + 1))
485
 
                                        if (PCB->Data->Layer[i].On == True &&
486
 
                                           GetGroupOfLayer(i) != group)
487
 
                                                break;
488
 
                                if (i != layer)
489
 
                                {
490
 
                                        ChangeGroupVisibility((int) i, True, True);
491
 
                                        XtVaSetValues(DrawingLayerMenuButton.W,
492
 
                                                XtNlabel, UNKNOWN(CURRENT->Name),
493
 
                                                XtNbackground, CURRENT->Color,
494
 
                                                NULL);
495
 
                                }
496
 
                                else
497
 
                                {
498
 
                                                /* everything else off, we can't turn this off too */
499
 
                                        XtVaSetValues(W, XtNstate, True, NULL);
500
 
                                        return;
501
 
                                }
502
 
                        }
503
 
 
504
 
                                /* switch layer group on/off */
505
 
                        ChangeGroupVisibility(layer, state, False);
506
 
                        Redraw = True;
507
 
                        break;
508
 
                }
509
 
        }
510
 
        if (Redraw)
511
 
                UpdateAll();
 
479
  Boolean state, Redraw = False;
 
480
  long int layer = (long int) ClientData;
 
481
 
 
482
  /* get new state of widget */
 
483
  XtVaGetValues (W, XtNstate, &state, NULL);
 
484
 
 
485
  /* set redraw flag if object exists */
 
486
  switch (layer)
 
487
    {
 
488
    case MAX_LAYER + 1: /* settings for pins */
 
489
      PCB->PinOn = state;
 
490
      Redraw |= (PCB->Data->ElementN != 0);
 
491
      break;
 
492
 
 
493
    case MAX_LAYER + 2: /* settings for vias */
 
494
      PCB->ViaOn = state;
 
495
      Redraw |= (PCB->Data->ViaN != 0);
 
496
      break;
 
497
 
 
498
    case MAX_LAYER + 3: /* settings for invisible objects */
 
499
      PCB->InvisibleObjectsOn = state;
 
500
      PCB->Data->BACKSILKLAYER.On = (state && PCB->ElementOn);
 
501
      Redraw = True;
 
502
      break;
 
503
 
 
504
    case MAX_LAYER + 4: /* settings for rat lines */
 
505
      PCB->RatOn = state;
 
506
      Redraw |= (PCB->Data->RatN != 0);
 
507
      break;
 
508
 
 
509
    default:
 
510
      {
 
511
        int i, group;
 
512
 
 
513
        /* check if active layer is in the group;
 
514
         * if YES, make a different one active if possible
 
515
         */
 
516
        if ((group = GetGroupOfLayer (layer)) ==
 
517
            GetGroupOfLayer (MIN (MAX_LAYER, INDEXOFCURRENT)))
 
518
          {
 
519
            /* find next visible layer and make it
 
520
             * active so this one can be turned off
 
521
             */
 
522
            for (i = (layer + 1) % (MAX_LAYER + 1);
 
523
                 i != layer; i = (i + 1) % (MAX_LAYER + 1))
 
524
              if (PCB->Data->Layer[i].On == True &&
 
525
                  GetGroupOfLayer (i) != group)
 
526
                break;
 
527
            if (i != layer)
 
528
              {
 
529
                ChangeGroupVisibility ((int) i, True, True);
 
530
                XtVaSetValues (DrawingLayerMenuButton.W,
 
531
                               XtNlabel, UNKNOWN (CURRENT->Name),
 
532
                               XtNbackground, CURRENT->Color, NULL);
 
533
              }
 
534
            else
 
535
              {
 
536
                /* everything else off, we can't turn this off too */
 
537
                XtVaSetValues (W, XtNstate, True, NULL);
 
538
                return;
 
539
              }
 
540
          }
 
541
 
 
542
        /* switch layer group on/off */
 
543
        ChangeGroupVisibility (layer, state, False);
 
544
        Redraw = True;
 
545
        break;
 
546
      }
 
547
    }
 
548
  if (Redraw)
 
549
    UpdateAll ();
512
550
}
513
551
 
514
552
/* ---------------------------------------------------------------------------
517
555
 *   drawing layer
518
556
 * returns popup shell widget
519
557
 */
520
 
void InitControlPanel(Widget Parent, Widget Top, Widget Left)
 
558
void
 
559
InitControlPanel (Widget Parent, Widget Top, Widget Left)
521
560
{
522
 
        Widget  masterform,
523
 
                        visible,
524
 
                        drawing;
525
 
 
526
 
        masterform = XtVaCreateManagedWidget("controlMasterForm", formWidgetClass,
527
 
                Parent,
528
 
                XtNfromHoriz, Left,
529
 
                XtNfromVert, Top,
530
 
                LAYOUT_TOP,
531
 
                NULL);
532
 
        InitOutputPanner(masterform, NULL, NULL);
533
 
        visible = XtVaCreateManagedWidget("onOffSelection", formWidgetClass,
534
 
                masterform,
535
 
                XtNfromVert, Output.panner,
536
 
                XtNfromHoriz, NULL,
537
 
                NULL);
538
 
        drawing = XtVaCreateManagedWidget("currentSelection", formWidgetClass,
539
 
                masterform,
540
 
                XtNfromVert, visible,
541
 
                XtNfromHoriz, NULL,
542
 
                NULL);
543
 
 
544
 
                /* we now add the other widgets to the two forms */
545
 
        AddOnOffSelection(visible);
546
 
        AddDrawingLayerSelection(drawing);
547
 
        Output.Control = masterform;
 
561
  Widget masterform, visible, drawing;
 
562
 
 
563
  masterform = XtVaCreateManagedWidget ("controlMasterForm", formWidgetClass,
 
564
                                        Parent,
 
565
                                        XtNfromHoriz, Left,
 
566
                                        XtNfromVert, Top, LAYOUT_TOP, NULL);
 
567
  InitOutputPanner (masterform, NULL, NULL);
 
568
  visible = XtVaCreateManagedWidget ("onOffSelection", formWidgetClass,
 
569
                                     masterform,
 
570
                                     XtNfromVert, Output.panner,
 
571
                                     XtNfromHoriz, NULL, NULL);
 
572
  drawing = XtVaCreateManagedWidget ("currentSelection", formWidgetClass,
 
573
                                     masterform,
 
574
                                     XtNfromVert, visible,
 
575
                                     XtNfromHoriz, NULL, NULL);
 
576
 
 
577
  /* we now add the other widgets to the two forms */
 
578
  AddOnOffSelection (visible);
 
579
  AddDrawingLayerSelection (drawing);
 
580
  Output.Control = masterform;
548
581
}
549
582
 
550
583
/* ---------------------------------------------------------------------------
551
584
 * updates label and sizes in control panel
552
585
 */
553
 
void UpdateControlPanel(void)
 
586
void
 
587
UpdateControlPanel (void)
554
588
{
555
 
        UpdateOnOffSelection();
556
 
        UpdateDrawingLayerSelection();
 
589
  UpdateOnOffSelection ();
 
590
  UpdateDrawingLayerSelection ();
557
591
}
558
592
 
559
593
/* ---------------------------------------------------------------------------
560
594
 * callback routine, called when current mode is changed
561
595
 */
562
 
static void CB_SetMode(Widget W, XtPointer ClientData, XtPointer CallData)
 
596
static void
 
597
CB_SetMode (Widget W, XtPointer ClientData, XtPointer CallData)
563
598
{
564
 
        ModeButtonTypePtr       button;
565
 
        
566
 
                /* the radio group is determined by the widget of button 0 */
567
 
        button = (ModeButtonTypePtr) XawToggleGetCurrent(ModeButtons[0].W);
568
 
        SetMode(button ? button->Mode : NO_MODE);
 
599
  ModeButtonTypePtr button;
 
600
 
 
601
  /* the radio group is determined by the widget of button 0 */
 
602
  button = (ModeButtonTypePtr) XawToggleGetCurrent (ModeButtons[0].W);
 
603
  if (button)
 
604
    SetMode (button->Mode);
569
605
}
570
606
 
571
607
/* ---------------------------------------------------------------------------
572
608
 * updates the mode selection buttons to reflect the currently set mode
573
609
 */
574
 
void UpdateModeSelection(void)
 
610
void
 
611
UpdateModeSelection (void)
575
612
{
576
 
                /* reset all buttons if no mode is selected;
577
 
                 * the first buttons widget identifies the radio group whereas
578
 
                 * radioData points to the array member itself
579
 
                 */
580
 
        if (Settings.Mode == NO_MODE)
581
 
                XawToggleUnsetCurrent(ModeButtons[0].W);
582
 
        else
583
 
        {
584
 
                int     i;
 
613
  /* reset all buttons if no mode is selected;
 
614
   * the first buttons widget identifies the radio group whereas
 
615
   * radioData points to the array member itself
 
616
   */
 
617
  int i;
585
618
 
586
 
                for (i = 0; i < ENTRIES(ModeButtons); i++)
587
 
                        if (Settings.Mode == ModeButtons[i].Mode)
588
 
                        {
589
 
                                XawToggleSetCurrent(ModeButtons[0].W,
590
 
                                        (XtPointer) &ModeButtons[i]);
591
 
                                break;
592
 
                        }
593
 
        }
 
619
  for (i = 0; i < ENTRIES (ModeButtons); i++)
 
620
    if (Settings.Mode == ModeButtons[i].Mode)
 
621
      {
 
622
        XawToggleSetCurrent (ModeButtons[0].W, (XtPointer) & ModeButtons[i]);
 
623
        break;
 
624
      }
594
625
}
595
626
 
596
627
/* ---------------------------------------------------------------------------
597
628
 * initializes mode buttons
598
629
 */
599
 
Widget InitModeButtons(Widget Parent, Widget Top, Widget Left)
 
630
Widget
 
631
InitModeButtons (Widget Parent, Widget Top, Widget Left)
600
632
{
601
 
        int             i;
602
 
 
603
 
        for (i = 0; i < ENTRIES(ModeButtons); i++)
 
633
  Widget masterform;
 
634
  int i;
 
635
  static char *translations =
 
636
    "<EnterWindow>: highlight(Always) \n"
 
637
    "<LeaveWindow>: unhighlight() \n"
 
638
    "<Btn1Down>,<Btn1Up>: toggle() notify() \n";
 
639
  
 
640
  XtTranslations translationtable;
 
641
 
 
642
#if 0
 
643
  masterform = XtVaCreateManagedWidget ("toolMasterForm", formWidgetClass,
 
644
                                        Parent,
 
645
                                        XtNfromHoriz, Left,
 
646
                                        XtNfromVert, Top, LAYOUT_TOP, NULL);
 
647
#else
 
648
  masterform = Parent;
 
649
#endif
 
650
 
 
651
  translationtable = XtParseTranslationTable (translations);
 
652
 
 
653
  for (i = 0; i < ENTRIES (ModeButtons); i++)
 
654
    {
 
655
      Pixmap bitmap;
 
656
 
 
657
      /* create background pixmap */
 
658
      bitmap = XCreateBitmapFromData (Dpy, XtWindow (Parent),
 
659
                                      (char *) ModeButtons[i].Bitmap,
 
660
                                      ModeButtons[i].Width,
 
661
                                      ModeButtons[i].Height);
 
662
 
 
663
      /* create radio button; use label only if pixmap creation failed
 
664
       * layout has to be set here else X11R4 fails
 
665
       */
 
666
      if (bitmap != BadAlloc)
 
667
        ModeButtons[i].W = XtVaCreateManagedWidget (ModeButtons[i].Name,
 
668
                                                    toggleWidgetClass,
 
669
                                                    masterform,
 
670
                                                    XtNbitmap, bitmap,
 
671
                                                    XtNfromHoriz, Left,
 
672
                                                    XtNfromVert, Top,
 
673
                                                    XtNtranslations,
 
674
                                                    translationtable,
 
675
                                                    LAYOUT_TOP, NULL);
 
676
      else
 
677
        ModeButtons[i].W = XtVaCreateManagedWidget (ModeButtons[i].Name,
 
678
                                                    toggleWidgetClass,
 
679
                                                    masterform,
 
680
                                                    XtNlabel,
 
681
                                                    ModeButtons[i].Label,
 
682
                                                    XtNfromHoriz, Left,
 
683
                                                    XtNfromVert, Top,
 
684
                                                    LAYOUT_TOP, NULL);
 
685
 
 
686
      XtAddEventHandler (ModeButtons[i].W, EnterWindowMask, False,
 
687
                         CB_StopScroll, NULL);
 
688
      /* the first entry identifies the radiogroup,
 
689
       * we have to make sure that no NULL is passed to XtNradioData
 
690
       */
 
691
      XtVaSetValues (ModeButtons[i].W,
 
692
                     XtNradioGroup, ModeButtons[0].W,
 
693
                     XtNradioData, (XtPointer) & ModeButtons[i], NULL);
 
694
      XtAddCallback (ModeButtons[i].W, XtNcallback,
 
695
                     CB_SetMode, (XtPointer) & ModeButtons[i]);
 
696
 
 
697
      /* update position for next widget */
 
698
      if (i % BUTTONS_PER_ROW == BUTTONS_PER_ROW - 1)
604
699
        {
605
 
                Pixmap  bitmap;
606
 
 
607
 
                        /* create background pixmap */
608
 
                bitmap = XCreateBitmapFromData(Dpy, XtWindow(Parent),
609
 
                        ModeButtons[i].Bitmap, ModeButtons[i].Width, ModeButtons[i].Height);
610
 
 
611
 
                        /* create radio button; use label only if pixmap creation failed
612
 
                         * layout has to be set here else X11R4 fails
613
 
                         */
614
 
                if (bitmap != BadAlloc)
615
 
                        ModeButtons[i].W = XtVaCreateManagedWidget(ModeButtons[i].Name,
616
 
                                toggleWidgetClass,
617
 
                                Parent,
618
 
                                XtNbitmap, bitmap,
619
 
                                XtNfromHoriz, Left,
620
 
                                XtNfromVert, Top,
621
 
                                LAYOUT_TOP,
622
 
                                NULL);
623
 
                else
624
 
                        ModeButtons[i].W = XtVaCreateManagedWidget(ModeButtons[i].Name,
625
 
                                toggleWidgetClass,
626
 
                                Parent,
627
 
                                XtNlabel, ModeButtons[i].Label,
628
 
                                XtNfromHoriz, Left,
629
 
                                XtNfromVert, Top,
630
 
                                LAYOUT_TOP,
631
 
                                NULL);
632
 
 
633
 
                        /* the first entry identifies the radiogroup,
634
 
                         * we have to make sure that no NULL is passed to XtNradioData
635
 
                         */
636
 
                XtVaSetValues(ModeButtons[i].W,
637
 
                        XtNradioGroup, ModeButtons[0].W,
638
 
                        XtNradioData, (XtPointer) &ModeButtons[i],
639
 
                        NULL);
640
 
                XtAddCallback(ModeButtons[i].W, XtNcallback,
641
 
                        CB_SetMode, (XtPointer) &ModeButtons[i]);
642
 
 
643
 
                        /* update position for next widget */
644
 
                if (i % BUTTONS_PER_ROW == BUTTONS_PER_ROW - 1)
645
 
                {
646
 
                        Left = NULL;
647
 
                        Top = ModeButtons[i].W;
648
 
                }
649
 
                else
650
 
                        Left = ModeButtons[i].W;
 
700
          Left = NULL;
 
701
          Top = ModeButtons[i].W;
651
702
        }
652
 
        return(ModeButtons[i-1].W);
 
703
      else
 
704
        Left = ModeButtons[i].W;
 
705
    }
 
706
  return (ModeButtons[i - 1].W);
653
707
}