summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/mpeg/source/mpeg_mib/mibMenu.cpp
blob: ae5d4490305763cf1fa90e1f3eb7b8db3b4d3fbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* $Id$ */

/* Copyright (c) 1994 The Geometry Center; University of Minnesota
   1300 South Second Street;  Minneapolis, MN  55454, USA;

This file is free software; you can redistribute it and/or modify it only
under the the terms of the GNU GENERAL PUBLIC LICENSE which should be
included along with thisw file.  This software may be obtained via anonymous
ftp from geom.umn.edu; email: software@geom.umn.edu. */

/* Author: Daeron Meyer */

#include "mibload.h"
#include "mibwidgets.h"

ACE_RCSID(mpeg_mib, mibMenu, "$Id$")

extern Display	*dpy;
extern GC	mib_gc;
static int	delhandler; /* delay adding event handler until menu
					is actually created */

/* Code for Menu */
/*****************************************************************************/

mib_Widget *mib_create_Menu(mib_Widget *parent, char *name, char *label,
		int posx, int posy, int width, int height, int mib_fill)
{
  mib_Widget	*temp;
  mib_Menu	*myres;
  Widget	 wtemp;
  char		 label_temp[50];
  Arg		 args[20];
  int		 n;

  /* create the new widget and add it to the tree */

  temp = mib_new_mib_Widget();
  if (mib_fill == WDEFAULT)
    mib_add_backward(temp, parent);
  else
    mib_add_mib_Widget(temp, parent);

  myres = (mib_Menu *)ACE_OS::malloc(sizeof(mib_Menu));

  /* initialize public resources */

  if (mib_fill == WDEFAULT)
  {
    temp->name = (char *)ACE_OS::malloc(strlen(name)+1);
    strcpy(temp->name,name);
  }
  temp->mib_class = (char *)ACE_OS::malloc(8);
  sprintf(temp->mib_class,"Menu");
  temp->mib_class_num = MIB_MENU;
  temp->width = width;
  temp->height = height;
  temp->topOffset = posy;
  temp->leftOffset = posx;
  temp->bottomOffset = 0;
  temp->rightOffset = 0;
  temp->topAttachment = 1;
  temp->leftAttachment = 1;
  temp->bottomAttachment = 0;
  temp->rightAttachment = 0;

  temp->mib_allowresize = 0;

  /* initialize private resources */

  temp->myres = (void *)myres;
  myres->numitems = 0;

  /* create Xt widget */

  n = 0;

  if (mib_fill == WDEFAULT)
  {
    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
    XtSetArg (args[n], XmNleftOffset, posx);n++;
    XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
    XtSetArg (args[n], XmNtopOffset, posy);n++;
  }
  XtSetArg (args[n], XmNrubberPositioning, False); n++;

  temp->me = XtCreateManagedWidget(name, xmRowColumnWidgetClass,
                temp->parent->me, args, n);

  n = 0;

  delhandler = 1;
  if (mib_fill == WDEFAULT)
  {
    delhandler = 0;
    myres->numitems = 3;
    myres->my_menu = (MenuItem *)ACE_OS::malloc(sizeof(MenuItem) * (myres->numitems+1));
    myres->items = (Widget *)ACE_OS::malloc(sizeof(Widget) * myres->numitems);
    sprintf(label_temp, "Item 1");
    myres->my_menu[0].label = (char *)ACE_OS::malloc(strlen(label_temp)+1);
    strcpy(myres->my_menu[0].label,label_temp);
    myres->my_menu[0].wclass = &xmPushButtonGadgetClass;
    myres->my_menu[0].mnemonic = '1';
    myres->my_menu[0].accelerator = NULL;
    myres->my_menu[0].accel_text = NULL;
    myres->my_menu[0].accel_text = NULL;
    myres->my_menu[0].callback = NULL;
    myres->my_menu[0].callback_data = NULL;
    myres->my_menu[0].subitems = (struct _menu_item *)1;

    sprintf(label_temp, "Item 2");
    myres->my_menu[1].label = (char *)ACE_OS::malloc(strlen(label_temp)+1);
    strcpy(myres->my_menu[1].label,label_temp);
    myres->my_menu[1].wclass = &xmPushButtonGadgetClass;
    myres->my_menu[1].mnemonic = '2';
    myres->my_menu[1].accelerator = NULL;
    myres->my_menu[1].accel_text = NULL;
    myres->my_menu[1].accel_text = NULL;
    myres->my_menu[1].callback = NULL;
    myres->my_menu[1].callback_data = NULL;
    myres->my_menu[1].subitems = (struct _menu_item *)1;

    sprintf(label_temp, "Item 3");
    myres->my_menu[2].label = (char *)ACE_OS::malloc(strlen(label_temp)+1);
    strcpy(myres->my_menu[2].label,label_temp);
    myres->my_menu[2].wclass = &xmPushButtonGadgetClass;
    myres->my_menu[2].mnemonic = '2';
    myres->my_menu[2].accelerator = NULL;
    myres->my_menu[2].accel_text = NULL;
    myres->my_menu[2].accel_text = NULL;
    myres->my_menu[2].callback = NULL;
    myres->my_menu[2].callback_data = NULL;
    myres->my_menu[2].subitems = (struct _menu_item *)1;

    myres->my_menu[3].label = NULL;

    wtemp = BuildMenu(temp->me, XmMENU_OPTION, NULL, 'M', myres->my_menu);
    XtManageChild(wtemp);
  }

  if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  {

    /* default menu */

    if (!delhandler)
    {
      mib_apply_eventhandlers(wtemp, temp);
      mib_apply_eventhandlers(temp->me, temp);
    }
  }

  if (mib_fill == WEMPTY)
    delhandler = 0;

  return temp;
}

void mib_delete_Menu(mib_Widget *thisw)
{
  mib_Menu *temp = (mib_Menu *)thisw->myres;

  ACE_OS::free(temp);
}

void mib_save_Menu(mib_Widget *thisw, FILE *fout)
{
  mib_Menu *temp = (mib_Menu *)thisw->myres;
  int count;

  fprintf(fout, "numitems: %d\\n\\\n", temp->numitems);

  for (count=0; count < temp->numitems; count++)
  {
    fprintf(fout, "item: \\\"%s\\\"\\n\\\n", temp->my_menu[count].label);
  }

}

int mib_load_Menu(mib_Widget *thisw, mib_Buffer *fin)
{
  char          res[MI_MAXSTRLEN];
  char          val[MI_MAXSTRLEN];
  int		count, vallen;
  Widget	wtemp;
  mib_Menu     *myres = (mib_Menu *)thisw->myres;
  

  if (!mib_read_line(fin, res, val))
    return 0;

  if (!strcmp(res, "numitems"))
  {
    myres->numitems = 0;
    sscanf(val, "%d", &(myres->numitems));
    if (!(myres->numitems))
      return 0;

    myres->my_menu = (MenuItem *)ACE_OS::malloc(sizeof(MenuItem) * (myres->numitems+1));
    myres->items = (Widget *)ACE_OS::malloc(sizeof(Widget) * myres->numitems);
    for (count = 0; count < myres->numitems; count++)
    {
      if (!mib_read_line(fin, res, val))
	return 0;
      vallen =ACE_OS::strlen (val);
      if (vallen < 2)
	return 0;
      val[vallen-1] = '\0';
      myres->my_menu[count].label = (char *)ACE_OS::malloc(vallen-1);
      sprintf(myres->my_menu[count].label, "%s", &(val[1]));
      myres->my_menu[count].wclass = &xmPushButtonGadgetClass;
      myres->my_menu[count].mnemonic = NULL;
      myres->my_menu[count].accelerator = NULL;
      myres->my_menu[count].accel_text = NULL;
      myres->my_menu[count].accel_text = NULL;
      myres->my_menu[count].callback = NULL;
      myres->my_menu[count].callback_data = NULL;
      myres->my_menu[count].subitems = (struct _menu_item *)1;
    }
    myres->my_menu[myres->numitems].label = NULL;

    wtemp = BuildMenu(thisw->me, XmMENU_OPTION, NULL, NULL, myres->my_menu);
    XtManageChild(wtemp);

    if (delhandler)
    {
      mib_apply_eventhandlers(wtemp, thisw);
      mib_apply_eventhandlers(thisw->me, thisw);
    }
    else
      thisw->me = wtemp;

    for (count = 0; count < myres->numitems; count++)
    {
      /* thisw hack extracts the widget for each item in the menu
	 for possible use by the programmer */
      myres->items[count] = (Widget)(myres->my_menu[count].subitems);
    }
      
  }
  else
    return 0;

  if (!mib_read_line(fin, res, val))
    return 0;
  if (ACE_OS::strcmp (res,"EndWidget"))
    return 0;

  return 1;
}