FreeWRL/FreeX3D  3.0.0
orig.fwMotifWindow.c
1 /*
2 
3  FreeWRL support library.
4  Create Motif window, widget, menu. Manage events.
5 
6 */
7 
8 /****************************************************************************
9  This file is part of the FreeWRL/FreeX3D Distribution.
10 
11  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12 
13  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14  it under the terms of the GNU Lesser Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25 ****************************************************************************/
26 
27 #include <config.h>
28 #define MAXSTAT 200
29 // OLD_IPHONE_AQUA #if !(defined(IPHONE) || defined(_ANDROID) || defined(AQUA))
30 #if !(defined(_ANDROID))
31 
32 #include <system.h>
33 #include <display.h>
34 #if KEEP_FV_INLIB
35 #include <internal.h>
36 
37 #include <libFreeWRL.h>
38 
39 #include <threads.h>
40 
41 #include "../main/MainLoop.h"
42 #include "../vrml_parser/Structs.h"
43 #include "../opengl/OpenGL_Utils.h"
44 #include "../scenegraph/Viewer.h"
45 #include "../ui/common.h"
46 
47 #include <Xm/MainW.h>
48 #include <Xm/RowColumn.h>
49 #include <Xm/PushB.h>
50 #include <Xm/ToggleB.h>
51 #include <Xm/CascadeB.h>
52 #include <Xm/TextF.h>
53 #include <Xm/Separator.h>
54 #include <Xm/PanedW.h>
55 #include <Xm/Text.h>
56 #include <Xm/ScrolledW.h>
57 #include <Xm/FileSB.h>
58 #include <Xm/SelectioB.h>
59 #include <Xm/MessageB.h>
60 #include <Xm/DrawingA.h> /* simple drawing area */
61 
62 #define ABOUT_FREEWRL "FreeWRL Version %s\n \
63 %s %s.\n \n \
64 FreeWRL is a VRML/X3D Browser for OS X and Unix.\n \n \
65 Thanks to the Open Source community for all the help received.\n \
66 http://freewrl.sf.net"
67 
68 #define DJ_KEEP_COMPILER_WARNING 0
69 
70 void setDefaultBackground(int colour);
71 
72 #define colourBlack 0
73 
74 #define colourWhite 9
75 
76 /* because of threading issues in Linux, if we can only use 1 thread, we
77  delay setting of info until this time. */
78 int colbut; int colbutChanged = FALSE;
79 int headbut; int headbutChanged = FALSE;
80 int fl, ex, wa; int navbutChanged = FALSE;
81 int msgChanged = FALSE;
82 char *consMsg = NULL; int consmsgChanged = FALSE;
83 
84 char fpsstr[MAXSTAT+20];
85 
86 /* static String defaultResources[200]; */
87 int MainWidgetRealized = FALSE;
88 int msgWindowOnscreen = FALSE;
89 int consWindowOnscreen = FALSE;
90 
91 XtAppContext Xtcx;
92 Widget freewrlTopWidget, mainw, menubar,menuworkwindow;
93 Widget menumessagewindow = NULL; /* tested against NULL in code */
94 Widget frame, freewrlDrawArea;
95 Widget headlightButton;
96 Widget collisionButton;
97 Widget walkButton, flyButton, examineButton;
98 Widget menumessageButton;
99 Widget consolemessageButton;
100 Widget consoleTextArea;
101 Widget consoleTextWidget;
102 Widget about_widget;
103 Widget newFileWidget;
104 Widget tex128_button, tex256_button, texFull_button, texturesFirstButton;
105 
106 /* colour selection for default background */
107 Widget backgroundColourSelector[colourWhite+1];
108 String BackString[] = {"Black Background", "Red Background", "Green Background", "Blue Background", "Magenta Background", "Yellow Background", "Cyan Background", "Grey Background", "Orange Background", "White Background"};
109 float backgroundColours[] = {
110  0.0, 0.0, 0.0, /* black */
111  0.8, 0.0, 0.0, /* red */
112  0.0, 0.8, 0.0, /* green */
113  0.0, 0.0, 0.8, /* blue */
114  0.8, 0.0, 0.8, /* magenta */
115  0.8, 0.8, 0.0, /* yellow */
116  0.0, 0.8, 0.8, /* cyan */
117  0.8, 0.8, 0.8, /* grey */
118  1.0, 0.6, 0.0, /* orange */
119  1.0, 1.0, 1.0}; /* white */
120 
121 Arg args[10];
122 Arg buttonArgs[10]; int buttonArgc = 0;
123 Arg textArgs[10]; int textArgc = 0;
124 
125 extern char myMenuStatus[];
126 
127 void fv_createMenuBar(void);
128 void fv_createDrawingFrame(void);
129 
130 
131 void myXtManageChild (int c, Widget child)
132 {
133 #ifdef XTDEBUG
134  printf ("at %d, managing %d\n",c, child);
135 #endif
136  if (child != NULL) XtManageChild (child);
137 }
138 
139 
140 /* see if/when we become iconified - if so, dont bother doing OpenGL stuff */
141 void StateWatcher (Widget w, XtPointer unused, XEvent *event, Boolean *cont)
142 {
143 #ifdef XEVENT_VERBOSE
144  // Used to track down TouchSensor loosing event with Motif (direct X11 is ok)
145  TRACE_MSG("freewrlTopWidget [StateWatch] went through (xm callback): widget %p event %p\n", (void*)w, (void*)event);
146 #endif
147  if (event->type == MapNotify) setDisplayed (TRUE);
148  else if (event->type == UnmapNotify) setDisplayed (FALSE);
149 }
150 
151 void fv_DrawArea_events (Widget w, XtPointer unused, XEvent *event, Boolean *cont)
152 {
153 #ifdef XEVENT_VERBOSE
154  // Used to track down TouchSensor loosing event with Motif (direct X11 is ok)
155 
156  XWindowAttributes attr;
157  XSetWindowAttributes set_attr;
158 
159  TRACE_MSG("fv_DrawArea event went through (xm callback): widget %p event %p\n", (void*)w, (void*)event);
160 
161  memset(&attr, 0, sizeof(attr));
162  memset(&set_attr, 0, sizeof(set_attr));
163 
164  /* Get window attributes and examine the event mask */
165  XGetWindowAttributes(Xdpy, Xwin, &attr);
166  TRACE_MSG("DrawArea event mask: %lu\n", attr.your_event_mask);
167  if (!(attr.your_event_mask & PointerMotionMask)) {
168  TRACE_MSG("DrawArea window not configured to receive PointerMotionMask...\n");
169  }
170  /* Set event mask to catch mouse motion events */
171  set_attr.event_mask = attr.your_event_mask | PointerMotionMask;
172  XChangeWindowAttributes(Xdpy, Xwin, CWEventMask, &set_attr);
173 
174 #endif
175 
176  /* This event should be passed to FreeWRL (MainLoop) control */
177  DEBUG_XEV("EVENT through MOTIF\n");
178  handle_Xevents(*event);
179 }
180 
184 int fv_create_main_window(freewrl_params_t * params) //int argc, char *argv[])
185 {
186  int argc_out = 0;
187  char *argv_out[1] = { NULL };
188  Dimension width, height;
189  Arg initArgs[10]; int initArgc = 0;
190 
191  /* XtVaAppInitialize ??? */
192  XtSetArg(initArgs[initArgc], XmNlabelString, XmStringCreate(getWindowTitle(), XmSTRING_DEFAULT_CHARSET)); initArgc++;
193  XtSetArg(initArgs[initArgc], XmNheight, params->height); initArgc++;
194  XtSetArg(initArgs[initArgc], XmNwidth, params->width); initArgc++;
195  XtSetArg(initArgs[initArgc], XmNmappedWhenManaged, False); initArgc++;
196 
201  XtToolkitInitialize();
202  Xtcx = XtCreateApplicationContext();
203 
204  XtDisplayInitialize(Xtcx, Xdpy, "FreeWRL", "FreeWRL_class", NULL, 0, &argc_out, argv_out);
205 
206  freewrlTopWidget = XtAppCreateShell("FreeWRL", "FreeWRL_class", applicationShellWidgetClass, Xdpy, initArgs, initArgc);
207 
208  if (!freewrlTopWidget) {
209  ERROR_MSG("Can't initialize Motif\n");
210  return FALSE;
211  }
212 
213  /* Inform Motif that we have our visual and colormap already ... (before top level is realized) */
214  XtVaSetValues(freewrlTopWidget,
215  XmNdepth, Xvi->depth,
216  XmNvisual, Xvi->visual,
217  XmNcolormap, colormap,
218  NULL);
219 
220  mainw = XmCreateMainWindow(freewrlTopWidget, getWindowTitle(), NULL, 0);
221  if (!mainw)
222  return FALSE;
223 
224  myXtManageChild(29, mainw);
225 
226  /* Create a menu bar. */
227  fv_createMenuBar();
228 
229  /* Create a framed drawing area for OpenGL rendering. */
230  fv_createDrawingFrame();
231 
232  /* Set up the application's window layout. */
233  XtVaSetValues(mainw,
234  XmNworkWindow, frame,
235  XmNcommandWindow, NULL,
236  XmNmenuBar, menubar,
237  XmNmessageWindow, menumessagewindow,
238  NULL);
239 
240 
241  XtRealizeWidget (freewrlTopWidget);
242 
243  /* FIXME: see fwBareWindow.c */
244  /* Roberto Gerson */
245  /* If -d is setted, so reparent the window */
246  if (params->winToEmbedInto != INT_ID_UNDEFINED){
247  printf("fwMotifWindow::Trying to reparent window: %ld, to new parent: %ld\n",
248  XtWindow(freewrlTopWidget),
249  params->winToEmbedInto);
250 
251  XReparentWindow(XtDisplay(freewrlTopWidget),
252  XtWindow(freewrlTopWidget),
253  (Window) params->winToEmbedInto, 0, 0);
254 
255  XMapWindow(XtDisplay(freewrlTopWidget), XtWindow(freewrlTopWidget));
256  }
257 
258  XFlush(XtDisplay(freewrlTopWidget));
259 
260  MainWidgetRealized = XtIsRealized(freewrlTopWidget); /*TRUE;*/
261  TRACE_MSG("fv_create_main_window: top widget realized: %s\n", BOOL_STR(MainWidgetRealized));
262 
263  /* let the user ask for this one We do it here, again, because on Ubuntu,
264  * this pops up on startup. Maybe because it has scrollbars, or other internal
265  * widgets? */
266  XtUnmanageChild(consoleTextWidget);
267 
268  Xwin = XtWindow(freewrlTopWidget);
269  GLwin = XtWindow(freewrlDrawArea);
270 
271  /* now, lets tell the OpenGL window what its dimensions are */
272 
273  XtVaGetValues(freewrlDrawArea, XmNwidth, &width, XmNheight, &height, NULL);
274  /* printf("%s,%d fv_create_main_window %d, %d\n",__FILE__,__LINE__,width,height); */
275  fv_setScreenDim(width,height);
276 
277  /* lets see when this goes iconic */
278  XtAddEventHandler(freewrlTopWidget, StructureNotifyMask, FALSE, StateWatcher, NULL);
279  /* all events for DrawArea should be passed to FreeWRL (MainLoop) control */
280  XtAddEventHandler(freewrlDrawArea, event_mask, False, fv_DrawArea_events, NULL);
281 
282  return TRUE;
283 }
284 
285 /************************************************************************
286 
287 Callbacks to handle button presses, etc.
288 
289 ************************************************************************/
290 
291 /* Label strings are "broken" on some Motifs. See:
292  * http://www.faqs.org/faqs/motif-faq/part5/
293  */
294 /* both of these fail on Ubuntu 6.06 */
295 /* diastring = XmStringCreateLtoR(ns,XmFONTLIST_DEFAULT_TAG); */
296 /*diastring = XmStringCreateLocalized(ns); */
297 
298 XmString xec_NewString(char *s)
299 {
300  XmString xms1;
301  XmString xms2;
302  XmString line;
303  XmString separator;
304  char *p;
305  char *t = XtNewString(s); /* Make a copy for strtok not to */
306  /* damage the original string */
307 
308  separator = XmStringSeparatorCreate();
309  p = strtok(t,"\n");
310  xms1 = XmStringCreateLocalized(p);
311 
312  /* FIXME: ???? why NULL here */
313  while ((p = strtok(NULL,"\n")))
314  {
315  line = XmStringCreateLocalized(p);
316  xms2 = XmStringConcat(xms1,separator);
317  XmStringFree(xms1);
318  xms1 = XmStringConcat(xms2,line);
319  XmStringFree(xms2);
320  XmStringFree(line);
321  }
322 
323  XmStringFree(separator);
324  XtFree(t);
325  return xms1;
326 }
327 
328 /* Callbacks */
329 void fv_aboutFreeWRLpopUp (Widget w, XtPointer data, XtPointer callData)
330 {
331 
332  int ac;
333  Arg args[10];
334  const char *ver;
335  char *msg, *rdr, *vendor;
336  XmString diastring;
337  ac = 0;
338 
339  ver = libFreeWRL_get_version();
340 
341  /* rdr = (char *)gglobal()->display.rdr_caps.renderer; */
342  rdr = "hello";
343  /* vendor = (char *)gglobal()->display.rdr_caps.vendor; */
344  vendor = "hello";
345 
346  msg = MALLOC(void *, strlen(ABOUT_FREEWRL) + strlen(ver)
347  + strlen(rdr) + strlen(vendor));
348  sprintf(msg, ABOUT_FREEWRL, ver, rdr, vendor);
349 
350  diastring = xec_NewString(msg);
351  XtSetArg(args[ac], XmNmessageString, diastring); ac++;
352  XtSetValues(about_widget, args, ac);
353  XmStringFree(diastring);
354  FREE(msg);
355 
356  myXtManageChild(2,about_widget);
357 }
358 
359 /* quit selected */
360 void fv_quitMenuBar (Widget w, XtPointer data, XtPointer callData)
361 {
362  fwl_doQuit(__FILE__,__LINE__);
363 }
364 
365 void fv_reloadFile (Widget w, XtPointer data, XtPointer callData)
366 {
367  ConsoleMessage ("reloading %s", BrowserFullPath);
368  /* FIXME: implement reload function */
369 }
370 
371 void fv_ViewpointFirst (Widget w, XtPointer data, XtPointer callData) {
372  fwl_First_ViewPoint();
373 }
374 
375 void fv_ViewpointLast (Widget w, XtPointer data, XtPointer callData)
376 {
377  fwl_Last_ViewPoint();
378 }
379 
380 void fv_ViewpointNext (Widget w, XtPointer data, XtPointer callData)
381 {
382  fwl_Next_ViewPoint();
383 }
384 
385 void fv_ViewpointPrev (Widget w, XtPointer data, XtPointer callData)
386 {
387  fwl_Prev_ViewPoint();
388 }
389 
390 /* selecting default background colours */
391 
392 void fv_BackColour(Widget w, XtPointer data, XtPointer callData)
393 {
394  int color = (int) data;
395  setDefaultBackground(color);
396 }
397 
398 void fv_Tex128(Widget w, XtPointer data, XtPointer callData)
399 {
400  /* does nothing right now */
401 }
402 
403 void fv_Tex256(Widget w, XtPointer data, XtPointer callData)
404 {
405  /* does nothing right now */
406 }
407 
408 void fv_TexFull(Widget w, XtPointer data, XtPointer callData)
409 {
410  /* does nothing right now */
411 }
412 
413 
414 /* do we want a message window displaying fps, viewpoint, etc? */
415 void fv_toggleMessagebar (Widget w, XtPointer data, XtPointer callData)
416 {
417  msgWindowOnscreen = !msgWindowOnscreen; /* keep track of state */
418  XmToggleButtonSetState (menumessageButton,msgWindowOnscreen,FALSE); /* display blip if on */
419  if (msgWindowOnscreen) myXtManageChild (3,menumessagewindow); /* display (or not) message window */
420  else XtUnmanageChild (menumessagewindow);
421 }
422 
423 /* do we want a console window displaying errors, etc? */
424 void fv_toggleConsolebar (Widget w, XtPointer data, XtPointer callData)
425 {
426  consWindowOnscreen = !consWindowOnscreen; /* keep track of state */
427  XmToggleButtonSetState (consolemessageButton,consWindowOnscreen,FALSE); /* display blip if on */
428  if (consWindowOnscreen) myXtManageChild (30,consoleTextWidget); /* display (or not) console window */
429  else XtUnmanageChild (consoleTextWidget);
430 }
431 
432 void fv_WalkMode (Widget w, XtPointer data, XtPointer callData)
433 {
434  fwl_set_viewer_type (VIEWER_WALK);
435 }
436 
437 void fv_ExamineMode (Widget w, XtPointer data, XtPointer callData)
438 {
439  fwl_set_viewer_type (VIEWER_EXAMINE);
440 }
441 
442 void fv_FlyMode (Widget w, XtPointer data, XtPointer callData)
443 {
444  fwl_set_viewer_type (VIEWER_FLY);
445 }
446 
447 void fv_Headlight (Widget w, XtPointer data, XtPointer callData)
448 {
449  fwl_toggle_headlight();
450 }
451 
452 void fv_Collision (Widget w, XtPointer data, XtPointer callData)
453 {
454 /* fwl_setp_collision(!fwl_getp_collision());*/
455  toggle_collision();
456 }
457 
458 void fv_ViewpointStraighten (Widget w, XtPointer data, XtPointer callData)
459 {
460  printf ("not yet implemented\n");
461 }
462 
463 /* file selection dialog box, ok button pressed */
464 void fv_fileSelectPressed (Widget w, XtPointer data, XmFileSelectionBoxCallbackStruct *callData)
465 {
466  char *newfile;
467 
468  /* get the filename */
469  XmStringGetLtoR(callData->value,
470  XmSTRING_DEFAULT_CHARSET, &newfile);
471 
472  if (!Anchor_ReplaceWorld(newfile)) {
473  /* error message */
474  }
475  XtUnmanageChild(w);
476 }
477 
478 /* file selection dialog box cancel button - just get rid of widget */
479 void fv_unManageMe (Widget widget, XtPointer client_data,
480  XmFileSelectionBoxCallbackStruct *selection)
481 {
482  XtUnmanageChild(widget);
483 }
484 
485 /* new file popup - user wants to load a new file */
486 void fv_newFilePopup(Widget cascade_button, char *text, XmPushButtonCallbackStruct *cbs)
487 {
488  myXtManageChild(4,newFileWidget);
489  XtPopup(XtParent(newFileWidget), XtGrabNone);
490 }
491 
492 #ifdef DOESNOTGETICONICSTATE
493 /* resize, configure events */
494 void fv_GLAreaexpose (Widget w, XtPointer data, XtPointer callData)
495 {
496  XmDrawingAreaCallbackStruct *cd = (XmDrawingAreaCallbackStruct *) callData;
497  switch (cd->reason) {
498  case XmCR_EXPOSE: printf ("got expose event \n");
499  default: printf ("not known event, %d\n",cd->reason);
500  }
501 }
502 #endif
503 
504 /* resize, configure events */
505 void fv_GLArearesize (Widget w, XtPointer data, XtPointer callData)
506 {
507 /* XmDrawingAreaCallbackStruct *cd = (XmDrawingAreaCallbackStruct *) callData; */
508  Dimension width, height;
509 
510  XtVaGetValues (w, XmNwidth, &width, XmNheight, &height, NULL);
511  /* printf("%s,%d GLArearesize %d, %d\n",__FILE__,__LINE__,width,height); */
512  fv_setScreenDim (width,height);
513 }
514 
515 /* Mouse, keyboard input when focus is in OpenGL window. */
516 void fv_GLAreainput (Widget w, XtPointer data, XtPointer callData)
517 {
518  XmDrawingAreaCallbackStruct *cd = (XmDrawingAreaCallbackStruct *) callData;
519 
520 #ifdef XTDEBUG
521  printEvent(*(cd->event));
522 #endif
523 
524  handle_Xevents(*(cd->event));
525 }
526 
527 
528 /* remove this button from this SelectionBox widget */
529 void fv_removeWidgetFromSelect (Widget parent,
530 #if NeedWidePrototypes
531  unsigned int
532 #else
533  unsigned char
534 #endif
535  button) {
536 
537  Widget tmp;
538 
539  tmp = XmSelectionBoxGetChild(parent, button);
540  if (tmp == NULL) {
541  printf ("hmmm - button does not exist\n");
542  } else {
543  XtUnmanageChild(tmp);
544  }
545 }
546 
547 /* start up the browser, and point it to www.crc.ca/FreeWRL */
548 void fv_freewrlHomePopup (Widget w, XtPointer data, XtPointer callData)
549 {
550 #if DJ_KEEP_COMPILER_WARNING
551  #define MAXLINE 2000
552 #endif
553  const char *browser;
554  char *sysline;
555  const char pattern[] = "%s http://www.crc.ca/FreeWRL &";
556 
557  browser = freewrl_get_browser_program();
558  if (!browser) {
559  browser = BROWSER;
560  }
561  sysline = MALLOC(char *, strlen(browser)+strlen(pattern));
562  sprintf(sysline, pattern, browser);
563 
564  freewrlSystem(sysline);
565 
566  FREE(sysline);
567 }
568 
569 #ifdef XTDEBUG
570 /* for debugging... */
571 printEvent (XEvent event)
572 {
573  switch (event.type) {
574  case KeyPress: printf ("KeyPress"); break;
575  case KeyRelease: printf ("KeyRelease"); break;
576  case ButtonPress: printf ("ButtonPress"); break;
577  case ButtonRelease: printf ("ButtonRelease"); break;
578  case MotionNotify: printf ("MotionNotify"); break;
579  case EnterNotify: printf ("EnterNotify"); break;
580  case LeaveNotify: printf ("LeaveNotify"); break;
581  case FocusIn: printf ("FocusIn"); break;
582  case FocusOut: printf ("FocusOut"); break;
583  case KeymapNotify: printf ("KeymapNotify"); break;
584  case Expose: printf ("Expose"); break;
585  case GraphicsExpose: printf ("GraphicsExpose"); break;
586  case NoExpose: printf ("NoExpose"); break;
587  case VisibilityNotify: printf ("VisibilityNotify"); break;
588  case CreateNotify: printf ("CreateNotify"); break;
589  case DestroyNotify: printf ("DestroyNotify"); break;
590  case UnmapNotify: printf ("UnmapNotify"); break;
591  case MapNotify: printf ("MapNotify"); break;
592  case MapRequest: printf ("MapRequest"); break;
593  case ReparentNotify: printf ("ReparentNotify"); break;
594  case ConfigureNotify: printf ("ConfigureNotify"); break;
595  case ConfigureRequest: printf ("ConfigureRequest"); break;
596  case GravityNotify: printf ("GravityNotify"); break;
597  case ResizeRequest: printf ("ResizeRequest"); break;
598  case CirculateNotify: printf ("CirculateNotify"); break;
599  case CirculateRequest: printf ("CirculateRequest"); break;
600  case PropertyNotify: printf ("PropertyNotify"); break;
601  case SelectionClear: printf ("SelectionClear"); break;
602  case SelectionRequest: printf ("SelectionRequest"); break;
603  case SelectionNotify: printf ("SelectionNotify"); break;
604  case ColormapNotify: printf ("ColormapNotify"); break;
605  case ClientMessage: printf ("ClientMessage"); break;
606  case MappingNotify: printf ("MappingNotify"); break;
607  default :printf ("Event out of range - %d",event.type);
608  }
609  printf ("\n");
610 }
611 #endif
612 
613 /* File pulldown menu */
614 void fv_createFilePulldown()
615 {
616  Widget menupane, btn, cascade;
617 
618  XmString mask;
619  int ac;
620  Arg args[10];
621 
622  /* Create the FileSelectionDialog */
623  memset(args, 0, sizeof(args));
624  ac = 0;
625  mask = XmStringCreateLocalized("*.x3d");
626  XtSetArg(args[ac], XmNdirMask, mask); ac++;
627 
628  /* newFileWidget = XmCreateFileSelectionDialog(menubar, "select", args, 1); */
629  newFileWidget = XmCreateFileSelectionDialog(mainw, "select", args, 1);
630 
631  XtAddCallback(newFileWidget, XmNokCallback, (XtCallbackProc)fv_fileSelectPressed, NULL);
632  XtAddCallback(newFileWidget, XmNcancelCallback, (XtCallbackProc)fv_unManageMe, NULL);
633  /* delete buttons not wanted */
634  fv_removeWidgetFromSelect(newFileWidget,XmDIALOG_HELP_BUTTON);
635  XtUnmanageChild(newFileWidget);
636 
637 
638  menupane = XmCreatePulldownMenu (menubar, "menupane", NULL, 0);
639  btn = XmCreatePushButton (menupane, "Reload", NULL, 0);
640  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_reloadFile, NULL);
641  myXtManageChild (5,btn);
642  btn = XmCreatePushButton (menupane, "New...", NULL, 0);
643  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_newFilePopup, NULL);
644  myXtManageChild (6,btn);
645 
646  btn = XmCreatePushButton (menupane, "Quit", NULL, 0);
647  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_quitMenuBar, NULL);
648  myXtManageChild (7,btn);
649  XtSetArg (args[0], XmNsubMenuId, menupane);
650  cascade = XmCreateCascadeButton (menubar, "File", args, 1);
651  myXtManageChild (8,cascade);
652 }
653 
654 /* Navigate pulldown menu */
655 void fv_createNavigatePulldown()
656 {
657  Widget cascade, btn, menupane;
658 
659  menupane = XmCreatePulldownMenu (menubar, "menupane", NULL, 0);
660 
661  /* Viewpoints */
662  btn = XmCreatePushButton (menupane, "First Viewpoint", NULL, 0);
663  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_ViewpointFirst, NULL);
664  myXtManageChild (30,btn);
665  btn = XmCreatePushButton (menupane, "Next Viewpoint", NULL, 0);
666  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_ViewpointNext, NULL);
667  myXtManageChild (9,btn);
668  btn = XmCreatePushButton (menupane, "Prev Viewpoint", NULL, 0);
669  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_ViewpointPrev, NULL);
670  myXtManageChild (10,btn);
671  btn = XmCreatePushButton (menupane, "Last Viewpoint", NULL, 0);
672  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_ViewpointLast, NULL);
673  myXtManageChild (31,btn);
674 
675 
676  /* Navigation Mode Selection */
677  myXtManageChild(11,XmCreateSeparator (menupane, "sep1", NULL, 0));
678 
679  walkButton = XtCreateManagedWidget("Walk Mode", xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
680  XtAddCallback (walkButton, XmNvalueChangedCallback, (XtCallbackProc)fv_WalkMode, NULL);
681  myXtManageChild (12,walkButton);
682 
683  examineButton = XtCreateManagedWidget("Examine Mode", xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
684  XtAddCallback (examineButton, XmNvalueChangedCallback, (XtCallbackProc)fv_ExamineMode, NULL);
685  myXtManageChild (13,examineButton);
686 
687  flyButton = XtCreateManagedWidget("Fly Mode", xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
688  XtAddCallback (flyButton, XmNvalueChangedCallback, (XtCallbackProc)fv_FlyMode, NULL);
689  myXtManageChild (14,flyButton);
690 
691  /* Headlight, Collision */
692  myXtManageChild(15,XmCreateSeparator (menupane, "sep1", NULL, 0));
693 
694  headlightButton = XtCreateManagedWidget("Headlight",
695  xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
696  XtAddCallback(headlightButton, XmNvalueChangedCallback,
697  (XtCallbackProc)fv_Headlight, NULL);
698  myXtManageChild (16,headlightButton);
699 
700  collisionButton = XtCreateManagedWidget("Collision",
701  xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
702  XtAddCallback(collisionButton, XmNvalueChangedCallback,
703  (XtCallbackProc)fv_Collision, NULL);
704  myXtManageChild (17,collisionButton);
705 
706  /* Straighten */
707  /* BUTTON NOT WORKING - so make insensitive */
708  XtSetArg (buttonArgs[buttonArgc], XmNsensitive, FALSE);
709  myXtManageChild(18,XmCreateSeparator (menupane, "sep1", NULL, 0));
710  btn = XmCreatePushButton (menupane, "Straighten", buttonArgs, buttonArgc+1); /* NOTE THE +1 here for sensitive */
711  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_ViewpointStraighten, NULL);
712  myXtManageChild (19,btn);
713 
714  consolemessageButton = XtCreateManagedWidget("Console Display",
715  xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
716  XtAddCallback(consolemessageButton, XmNvalueChangedCallback,
717  (XtCallbackProc)fv_toggleConsolebar, NULL);
718  myXtManageChild (21,consolemessageButton);
719  menumessageButton = XtCreateManagedWidget("Message Display",
720  xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
721  XtAddCallback(menumessageButton, XmNvalueChangedCallback,
722  (XtCallbackProc)fv_toggleMessagebar, NULL);
723  myXtManageChild (20,menumessageButton);
724 
725  XtSetArg (args[0], XmNsubMenuId, menupane);
726  cascade = XmCreateCascadeButton (menubar, "Navigate", args, 1);
727  myXtManageChild (22,cascade);
728 }
729 
730 /* Preferences pulldown menu */
731 void fv_createPreferencesPulldown()
732 {
733  Widget cascade, menupane;
734  int count;
735 
736  menupane = XmCreatePulldownMenu (menubar, "menupane", NULL, 0);
737 
738  /* texture size on loading */
739  myXtManageChild(11,XmCreateSeparator (menupane, "sep1", NULL, 0));
740 
741  tex128_button = XtCreateManagedWidget("128x128 Textures", xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
742  XtAddCallback (tex128_button, XmNvalueChangedCallback, (XtCallbackProc)fv_Tex128, NULL);
743  myXtManageChild (12,tex128_button);
744 
745  tex256_button = XtCreateManagedWidget("256x256 Textures", xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
746  XtAddCallback (tex256_button, XmNvalueChangedCallback, (XtCallbackProc)fv_Tex256, NULL);
747  myXtManageChild (13,tex256_button);
748 
749  texFull_button = XtCreateManagedWidget("Fullsize Textures", xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
750  XtAddCallback (texFull_button, XmNvalueChangedCallback, (XtCallbackProc)fv_TexFull, NULL);
751  myXtManageChild (14,texFull_button);
752 
753  /* default Background colour */
754  myXtManageChild(11,XmCreateSeparator (menupane, "sep1", NULL, 0));
755 
756  for (count = colourBlack; count <= colourWhite; count++ ){
757  backgroundColourSelector[count] =
758  XtCreateManagedWidget(BackString[count], xmToggleButtonWidgetClass, menupane, buttonArgs, buttonArgc);
759  XtAddCallback (backgroundColourSelector[count], XmNvalueChangedCallback, (XtCallbackProc)fv_BackColour, (XtPointer)count);
760  myXtManageChild (40,backgroundColourSelector[count]);
761  }
762  XmToggleButtonSetState (backgroundColourSelector[colourBlack], TRUE, FALSE);
763 
764  XtSetArg (args[0], XmNsubMenuId, menupane);
765  cascade = XmCreateCascadeButton (menubar, "Preferences", args, 1);
766  myXtManageChild (22,cascade);
767 }
768 
769 void fv_createHelpPulldown()
770 {
771  Widget btn, menupane, cascade;
772  int ac;
773  Arg args[10];
774 
775 
776  menupane = XmCreatePulldownMenu (menubar, "menupane", NULL, 0);
777 
778  /* Helpity stuff */
779  ac = 0;
780  /*
781  sprintf (ns,ABOUT_FREEWRL,getLibVersion(),"","");
782  diastring = xec_NewString(ns);
783 
784  XtSetArg(args[ac], XmNmessageString, diastring); ac++;
785  */
786  XtSetArg(args[ac], XmNmessageAlignment,XmALIGNMENT_CENTER); ac++;
787  about_widget = XmCreateInformationDialog(menubar, "about", args, ac);
788  XtAddCallback(about_widget, XmNokCallback, (XtCallbackProc)fv_unManageMe, NULL);
789  fv_removeWidgetFromSelect (about_widget, XmDIALOG_CANCEL_BUTTON);
790  /*
791  causes segfault on Core3 fv_removeWidgetFromSelect (about_widget, XmDIALOG_HELP_BUTTON);
792  */
793 
794 
795  btn = XmCreatePushButton (menupane, "About FreeWRL...", NULL, 0);
796  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_aboutFreeWRLpopUp, NULL);
797  myXtManageChild (23,btn);
798  btn = XmCreatePushButton (menupane, "FreeWRL Homepage...", NULL, 0);
799  XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_freewrlHomePopup, NULL);
800  myXtManageChild (24,btn);
801 
802  XtSetArg (args[0], XmNsubMenuId, menupane);
803  cascade = XmCreateCascadeButton (menubar, "Help", args, 1);
804  myXtManageChild (25,cascade);
805 }
806 
807 /**********************************/
808 void fv_createMenuBar(void)
809 {
810  Arg menuArgs[10]; int menuArgc = 0;
811 
812  /* create the menu bar */
813  memset(menuArgs, 0, sizeof(menuArgs));
814  menuArgc = 0;
815 
816  /* the following XtSetArg is not required; it only "pretties" up the display
817  in some circumstances. It came out in Motif 2.0, and is not always found */
818 #ifdef XmNscrolledWindowChildType
819  XtSetArg(menuArgs[menuArgc], XmNscrolledWindowChildType, XmMENU_BAR); menuArgc++;
820 #endif
821 
822  menubar = XmCreateMenuBar (mainw, "menubar", menuArgs, menuArgc);
823  myXtManageChild (26,menubar);
824 
825  menumessagewindow =
826  XtVaCreateWidget ("Message:", xmTextFieldWidgetClass, mainw,
827  XmNeditable, False,
828  XmNmaxLength, 200,
829  NULL);
830 
831  /* generic toggle button resources */
832  XtSetArg(buttonArgs[buttonArgc], XmCVisibleWhenOff, TRUE); buttonArgc++;
833  XtSetArg(buttonArgs[buttonArgc],XmNindicatorType,XmN_OF_MANY); buttonArgc++;
834 
835  if (!RUNNINGASPLUGIN) fv_createFilePulldown();
836  fv_createNavigatePulldown();
837  fv_createPreferencesPulldown();
838  fv_createHelpPulldown();
839 
840 }
841 
842 /**********************************************************************************/
843 /*
844  create a frame for FreeWRL, and for messages
845 */
846 void fv_createDrawingFrame(void)
847 {
848  /* frame holds everything here */
849  frame = XtVaCreateManagedWidget("form", xmPanedWindowWidgetClass, mainw, NULL);
850  consoleTextWidget = XtVaCreateManagedWidget ("console text widget", xmScrolledWindowWidgetClass, frame,
851  XmNtopAttachment, XmATTACH_FORM,
852  XmNleftAttachment, XmATTACH_FORM,
853  XmNrightAttachment, XmATTACH_FORM,
854  XmNworkWindow, consoleTextArea,
855  NULL);
856  consoleTextArea = XtVaCreateManagedWidget ("console text area ", xmTextWidgetClass, consoleTextWidget,
857  XmNrows, 5,
858  XmNcolumns, 0,
859  XmNeditable, False,
860  XmNeditMode, XmMULTI_LINE_EDIT,
861  NULL);
862 
863  /* create the FreeWRL OpenGL drawing area, and map it. */
864 
865 #if 0 /* MB: do not create a glwDrawingArea but a simple widget
866  we have our own initialization of OpenGL ...
867  in the near future we could remove completely the GLwDrawA files...
868  */
869  freewrlDrawArea = XtVaCreateManagedWidget ("freewrlDrawArea", glwDrawingAreaWidgetClass,
870  frame, "visualInfo", Xvi,
871  XmNtopAttachment, XmATTACH_WIDGET,
872  XmNbottomAttachment, XmATTACH_FORM,
873  XmNleftAttachment, XmATTACH_FORM,
874  XmNrightAttachment, XmATTACH_FORM,
875  NULL);
876 #endif
877 
878  freewrlDrawArea = XmCreateDrawingArea (frame, "drawing_a", NULL, 0);
879 
880 #ifdef DOESNOTGETICONICSTATE
881  XtAddCallback (freewrlDrawArea, XmNexposeCallback, fv_GLAreaexpose, NULL);
882 #endif
883 
884  XtAddCallback (freewrlDrawArea, XmNresizeCallback, fv_GLArearesize, NULL);
885 
886  myXtManageChild(27,freewrlDrawArea);
887 
888  /* let the user ask for this one */
889  XtUnmanageChild(consoleTextWidget);
890 }
891 
892 void setConsoleMessage (char *str)
893 {
894  char *tptr;
895  int nl;
896 
897  /* is the consoleTextWidget created yet?? */
898  if (IS_DISPLAY_INITIALIZED != TRUE) {
899  ERROR_MSG("display not initialized: can't write ConsoleMessage: %s\n", str);
900  } else {
901  /* make sure console window is on screen */
902  if (!consWindowOnscreen) {
903  consWindowOnscreen = TRUE;
904  myXtManageChild (1,consoleTextWidget); /* display console window */
905  XmToggleButtonSetState (consolemessageButton,consWindowOnscreen,FALSE); /* display blip if on */
906  }
907 
908  /* put the text here */
909  nl = strlen(str);
910  tptr = MALLOC (char *, nl+10);
911  strcpy (tptr,str);
912 
913  /* copy old string, if it exists */
914  FREE_IF_NZ (consMsg);
915  consMsg = tptr;
916  consmsgChanged = TRUE;
917  }
918 }
919 
920 
921 
922 void frontendUpdateButtons()
923 {
924  if (colbutChanged) {
925  XmToggleButtonSetState (collisionButton,colbut,FALSE);
926  colbutChanged = FALSE;
927  }
928  if (headbutChanged) {
929  XmToggleButtonSetState (headlightButton,headbut,FALSE);
930  headbutChanged = FALSE;
931  }
932  if (navbutChanged) {
933  XmToggleButtonSetState (walkButton,wa,FALSE);
934  XmToggleButtonSetState (flyButton,fl,FALSE);
935  XmToggleButtonSetState (examineButton,ex,FALSE);
936  navbutChanged = FALSE;
937  }
938  if (msgChanged) {
939  XmTextSetString(menumessagewindow,fpsstr);
940  msgChanged = FALSE;
941  }
942  if (consmsgChanged) {
943  /* printf ("frontendUpateButtons, consmggchanged, posn %d oldstr %s consmsg %s\n",
944  strlen(XmTextGetString(consoleTextArea)),
945  XmTextGetString(consoleTextArea),
946  consMsg);*/
947  XmTextInsert (consoleTextArea, strlen(XmTextGetString(consoleTextArea)),consMsg);
948  consmsgChanged = FALSE;
949  }
950 }
951 
952 void getMotifWindowedGLwin(Window *win)
953 {
954  *win = XtWindow(freewrlDrawArea);
955 }
956 
957 void setDefaultBackground(int colour)
958 {
959  int count;
960 
961  if ((colour<colourBlack) || (colour > colourWhite)) return; /* an error... */
962 
963  for (count = colourBlack; count <= colourWhite; count++) {
964  XmToggleButtonSetState (backgroundColourSelector[count], FALSE, FALSE);
965  }
966  XmToggleButtonSetState (backgroundColourSelector[colour], TRUE, FALSE);
967  setglClearColor (&(backgroundColours[colour*3]));
968 
969  /* rather use fwl_set_glClearColor (float red , float green , float blue , float alpha); */
970 
971 }
972 
973 
974 #endif /* IPHONE */
975 #endif /* KEEP_FV_INLIB */
Initialization.
Definition: libFreeWRL.h:71