28 #if !(defined(_ANDROID))
35 #include <libFreeWRL.h>
39 #include "../main/MainLoop.h"
40 #include "../vrml_parser/Structs.h"
41 #include "../opengl/OpenGL_Utils.h"
42 #include "../scenegraph/Viewer.h"
43 #include "../ui/common.h"
46 #include <Xm/RowColumn.h>
48 #include <Xm/ToggleB.h>
49 #include <Xm/CascadeB.h>
51 #include <Xm/Separator.h>
52 #include <Xm/PanedW.h>
54 #include <Xm/ScrolledW.h>
55 #include <Xm/FileSB.h>
56 #include <Xm/SelectioB.h>
57 #include <Xm/MessageB.h>
58 #include <Xm/DrawingA.h>
60 #define ABOUT_FREEWRL "FreeWRL Version %s\n \
62 FreeWRL is a VRML/X3D Browser for OS X and Unix.\n \n \
63 Thanks to the Open Source community for all the help received.\n \
64 http://freewrl.sf.net"
66 #define DJ_KEEP_COMPILER_WARNING 0
69 static int MainWidgetRealized = FALSE;
73 static Widget freewrlTopWidget, mainw, menubar;
74 static Widget frame, freewrlDrawArea;
75 static Widget about_widget;
76 static Widget newFileWidget;
78 static Arg buttonArgs[10];
static int buttonArgc = 0;
80 extern char myMenuStatus[];
82 static void fv_createMenuBar(
void);
83 static void fv_createDrawingFrame(
void);
86 static void myXtManageChild (
int c, Widget child)
89 printf (
"at %d, managing %d\n",c, child);
91 if (child != NULL) XtManageChild (child);
96 static void StateWatcher (Widget w, XtPointer unused, XEvent *event, Boolean *cont)
100 TRACE_MSG(
"freewrlTopWidget [StateWatch] went through (xm callback): widget %p event %p\n", (
void*)w, (
void*)event);
102 if (event->type == MapNotify) setDisplayed (TRUE);
103 else if (event->type == UnmapNotify) setDisplayed (FALSE);
106 static void fv_DrawArea_events (Widget w, XtPointer unused, XEvent *event, Boolean *cont)
108 #ifdef XEVENT_VERBOSE
111 XWindowAttributes attr;
112 XSetWindowAttributes set_attr;
114 TRACE_MSG(
"fv_DrawArea event went through (xm callback): widget %p event %p\n", (
void*)w, (
void*)event);
116 memset(&attr, 0,
sizeof(attr));
117 memset(&set_attr, 0,
sizeof(set_attr));
120 XGetWindowAttributes(Xdpy, Xwin, &attr);
121 TRACE_MSG(
"DrawArea event mask: %lu\n", attr.your_event_mask);
122 if (!(attr.your_event_mask & PointerMotionMask)) {
123 TRACE_MSG(
"DrawArea window not configured to receive PointerMotionMask...\n");
126 set_attr.event_mask = attr.your_event_mask | PointerMotionMask;
127 XChangeWindowAttributes(Xdpy, Xwin, CWEventMask, &set_attr);
132 DEBUG_XEV(
"EVENT through MOTIF\n");
133 handle_Xevents(*event);
142 char *argv_out[1] = { NULL };
143 Dimension width, height;
144 Arg initArgs[10];
int initArgc = 0;
147 XtSetArg(initArgs[initArgc], XmNlabelString, XmStringCreate(getWindowTitle(), XmSTRING_DEFAULT_CHARSET)); initArgc++;
148 XtSetArg(initArgs[initArgc], XmNheight, params->height); initArgc++;
149 XtSetArg(initArgs[initArgc], XmNwidth, params->width); initArgc++;
150 XtSetArg(initArgs[initArgc], XmNmappedWhenManaged, False); initArgc++;
156 XtToolkitInitialize();
157 Xtcx = XtCreateApplicationContext();
159 XtDisplayInitialize(Xtcx, Xdpy,
"FreeWRL",
"FreeWRL_class", NULL, 0, &argc_out, argv_out);
161 freewrlTopWidget = XtAppCreateShell(
"FreeWRL",
"FreeWRL_class", applicationShellWidgetClass, Xdpy, initArgs, initArgc);
163 if (!freewrlTopWidget) {
164 ERROR_MSG(
"Can't initialize Motif\n");
169 XtVaSetValues(freewrlTopWidget,
170 XmNdepth, Xvi->depth,
171 XmNvisual, Xvi->visual,
172 XmNcolormap, colormap,
175 mainw = XmCreateMainWindow(freewrlTopWidget, getWindowTitle(), NULL, 0);
179 myXtManageChild(29, mainw);
185 fv_createDrawingFrame();
189 XmNworkWindow, frame,
190 XmNcommandWindow, NULL,
195 XtRealizeWidget (freewrlTopWidget);
200 if (params->winToEmbedInto != INT_ID_UNDEFINED){
201 printf(
"fwMotifWindow::Trying to reparent window: %ld, to new parent: %ld\n",
202 XtWindow(freewrlTopWidget),
203 params->winToEmbedInto);
205 XReparentWindow(XtDisplay(freewrlTopWidget),
206 XtWindow(freewrlTopWidget),
207 (Window) params->winToEmbedInto, 0, 0);
209 XMapWindow(XtDisplay(freewrlTopWidget), XtWindow(freewrlTopWidget));
212 XFlush(XtDisplay(freewrlTopWidget));
214 MainWidgetRealized = XtIsRealized(freewrlTopWidget);
215 TRACE_MSG(
"fv_create_main_window: top widget realized: %s\n", BOOL_STR(MainWidgetRealized));
217 Xwin = XtWindow(freewrlTopWidget);
218 GLwin = XtWindow(freewrlDrawArea);
222 XtVaGetValues(freewrlDrawArea, XmNwidth, &width, XmNheight, &height, NULL);
224 fv_setScreenDim(width,height);
227 XtAddEventHandler(freewrlTopWidget, StructureNotifyMask, FALSE, StateWatcher, NULL);
229 XtAddEventHandler(freewrlDrawArea, event_mask, False, fv_DrawArea_events, NULL);
247 static XmString xec_NewString(
char *s)
254 char *t = XtNewString(s);
257 separator = XmStringSeparatorCreate();
259 xms1 = XmStringCreateLocalized(p);
262 while ((p = strtok(NULL,
"\n")))
264 line = XmStringCreateLocalized(p);
265 xms2 = XmStringConcat(xms1,separator);
267 xms1 = XmStringConcat(xms2,line);
272 XmStringFree(separator);
278 static void fv_aboutFreeWRLpopUp (Widget w, XtPointer data, XtPointer callData)
284 char *msg, *rdr, *vendor;
288 ver = libFreeWRL_get_version();
290 rdr = (
char *)glGetString(GL_RENDERER);
291 vendor = (
char *)glGetString(GL_VENDOR);
293 msg = MALLOC(
void *, strlen(ABOUT_FREEWRL) + strlen(ver)
294 + strlen(rdr) + strlen(vendor));
295 sprintf(msg, ABOUT_FREEWRL, ver, rdr, vendor);
297 diastring = xec_NewString(msg);
298 XtSetArg(args[ac], XmNmessageString, diastring); ac++;
299 XtSetValues(about_widget, args, ac);
300 XmStringFree(diastring);
303 myXtManageChild(2,about_widget);
307 static void fv_quitMenuBar (Widget w, XtPointer data, XtPointer callData)
309 fwl_doQuit(__FILE__,__LINE__);
312 static void fv_reloadFile (Widget w, XtPointer data, XtPointer callData)
314 ConsoleMessage (
"reloading %s", BrowserFullPath);
319 static void fv_fileSelectPressed (Widget w, XtPointer data, XmFileSelectionBoxCallbackStruct *callData)
324 XmStringGetLtoR(callData->value,
325 XmSTRING_DEFAULT_CHARSET, &newfile);
327 if (!Anchor_ReplaceWorld(newfile)) {
334 static void fv_unManageMe (Widget widget, XtPointer client_data,
335 XmFileSelectionBoxCallbackStruct *selection)
337 XtUnmanageChild(widget);
341 static void fv_newFilePopup(Widget cascade_button,
char *text, XmPushButtonCallbackStruct *cbs)
343 myXtManageChild(4,newFileWidget);
344 XtPopup(XtParent(newFileWidget), XtGrabNone);
347 #ifdef DOESNOTGETICONICSTATE
349 static void fv_GLAreaexpose (Widget w, XtPointer data, XtPointer callData)
351 XmDrawingAreaCallbackStruct *cd = (XmDrawingAreaCallbackStruct *) callData;
352 switch (cd->reason) {
353 case XmCR_EXPOSE: printf (
"got expose event \n");
354 default: printf (
"not known event, %d\n",cd->reason);
360 static void fv_GLArearesize (Widget w, XtPointer data, XtPointer callData)
363 Dimension width, height;
365 XtVaGetValues (w, XmNwidth, &width, XmNheight, &height, NULL);
367 fv_setScreenDim (width,height);
371 static void fv_removeWidgetFromSelect (Widget parent,
372 #
if NeedWidePrototypes
381 tmp = XmSelectionBoxGetChild(parent, button);
383 printf (
"hmmm - button does not exist\n");
385 XtUnmanageChild(tmp);
390 static void fv_freewrlHomePopup (Widget w, XtPointer data, XtPointer callData)
392 #if DJ_KEEP_COMPILER_WARNING
397 const char pattern[] =
"%s http://freewrl.sourceforge.net &";
399 browser = freewrl_get_browser_program();
403 sysline = MALLOC(
char *, strlen(browser)+strlen(pattern));
404 sprintf(sysline, pattern, browser);
406 freewrlSystem(sysline);
413 printEvent (XEvent event)
415 switch (event.type) {
416 case KeyPress: printf (
"KeyPress");
break;
417 case KeyRelease: printf (
"KeyRelease");
break;
418 case ButtonPress: printf (
"ButtonPress");
break;
419 case ButtonRelease: printf (
"ButtonRelease");
break;
420 case MotionNotify: printf (
"MotionNotify");
break;
421 case EnterNotify: printf (
"EnterNotify");
break;
422 case LeaveNotify: printf (
"LeaveNotify");
break;
423 case FocusIn: printf (
"FocusIn");
break;
424 case FocusOut: printf (
"FocusOut");
break;
425 case KeymapNotify: printf (
"KeymapNotify");
break;
426 case Expose: printf (
"Expose");
break;
427 case GraphicsExpose: printf (
"GraphicsExpose");
break;
428 case NoExpose: printf (
"NoExpose");
break;
429 case VisibilityNotify: printf (
"VisibilityNotify");
break;
430 case CreateNotify: printf (
"CreateNotify");
break;
431 case DestroyNotify: printf (
"DestroyNotify");
break;
432 case UnmapNotify: printf (
"UnmapNotify");
break;
433 case MapNotify: printf (
"MapNotify");
break;
434 case MapRequest: printf (
"MapRequest");
break;
435 case ReparentNotify: printf (
"ReparentNotify");
break;
436 case ConfigureNotify: printf (
"ConfigureNotify");
break;
437 case ConfigureRequest: printf (
"ConfigureRequest");
break;
438 case GravityNotify: printf (
"GravityNotify");
break;
439 case ResizeRequest: printf (
"ResizeRequest");
break;
440 case CirculateNotify: printf (
"CirculateNotify");
break;
441 case CirculateRequest: printf (
"CirculateRequest");
break;
442 case PropertyNotify: printf (
"PropertyNotify");
break;
443 case SelectionClear: printf (
"SelectionClear");
break;
444 case SelectionRequest: printf (
"SelectionRequest");
break;
445 case SelectionNotify: printf (
"SelectionNotify");
break;
446 case ColormapNotify: printf (
"ColormapNotify");
break;
447 case ClientMessage: printf (
"ClientMessage");
break;
448 case MappingNotify: printf (
"MappingNotify");
break;
449 default :printf (
"Event out of range - %d",event.type);
456 static void fv_createFilePulldown()
458 Widget menupane, btn, cascade;
465 memset(args, 0,
sizeof(args));
467 mask = XmStringCreateLocalized(
"*.x3d");
468 XtSetArg(args[ac], XmNdirMask, mask); ac++;
471 newFileWidget = XmCreateFileSelectionDialog(mainw,
"select", args, 1);
473 XtAddCallback(newFileWidget, XmNokCallback, (XtCallbackProc)fv_fileSelectPressed, NULL);
474 XtAddCallback(newFileWidget, XmNcancelCallback, (XtCallbackProc)fv_unManageMe, NULL);
476 fv_removeWidgetFromSelect(newFileWidget,XmDIALOG_HELP_BUTTON);
477 XtUnmanageChild(newFileWidget);
480 menupane = XmCreatePulldownMenu (menubar,
"menupane", NULL, 0);
481 btn = XmCreatePushButton (menupane,
"Reload", NULL, 0);
482 XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_reloadFile, NULL);
483 myXtManageChild (5,btn);
484 btn = XmCreatePushButton (menupane,
"New...", NULL, 0);
485 XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_newFilePopup, NULL);
486 myXtManageChild (6,btn);
488 btn = XmCreatePushButton (menupane,
"Quit", NULL, 0);
489 XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_quitMenuBar, NULL);
490 myXtManageChild (7,btn);
491 XtSetArg (args[0], XmNsubMenuId, menupane);
492 cascade = XmCreateCascadeButton (menubar,
"File", args, 1);
493 myXtManageChild (8,cascade);
496 static void fv_createHelpPulldown()
498 Widget btn, menupane, cascade;
503 menupane = XmCreatePulldownMenu (menubar,
"menupane", NULL, 0);
513 XtSetArg(args[ac], XmNmessageAlignment,XmALIGNMENT_CENTER); ac++;
514 about_widget = XmCreateInformationDialog(menubar,
"about", args, ac);
515 XtAddCallback(about_widget, XmNokCallback, (XtCallbackProc)fv_unManageMe, NULL);
516 fv_removeWidgetFromSelect (about_widget, XmDIALOG_CANCEL_BUTTON);
522 btn = XmCreatePushButton (menupane,
"About FreeWRL...", NULL, 0);
523 XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_aboutFreeWRLpopUp, NULL);
524 myXtManageChild (23,btn);
525 btn = XmCreatePushButton (menupane,
"FreeWRL Homepage...", NULL, 0);
526 XtAddCallback (btn, XmNactivateCallback, (XtCallbackProc)fv_freewrlHomePopup, NULL);
527 myXtManageChild (24,btn);
529 XtSetArg (args[0], XmNsubMenuId, menupane);
530 cascade = XmCreateCascadeButton (menubar,
"Help", args, 1);
531 myXtManageChild (25,cascade);
535 static void fv_createMenuBar(
void)
537 Arg menuArgs[10];
int menuArgc = 0;
540 memset(menuArgs, 0,
sizeof(menuArgs));
545 #ifdef XmNscrolledWindowChildType
546 XtSetArg(menuArgs[menuArgc], XmNscrolledWindowChildType, XmMENU_BAR); menuArgc++;
549 menubar = XmCreateMenuBar (mainw,
"menubar", menuArgs, menuArgc);
550 myXtManageChild (26,menubar);
553 XtSetArg(buttonArgs[buttonArgc], XmCVisibleWhenOff, TRUE); buttonArgc++;
554 XtSetArg(buttonArgs[buttonArgc],XmNindicatorType,XmN_OF_MANY); buttonArgc++;
556 if (!RUNNINGASPLUGIN) fv_createFilePulldown();
557 fv_createHelpPulldown();
565 static void fv_createDrawingFrame(
void)
568 frame = XtVaCreateManagedWidget(
"form", xmPanedWindowWidgetClass, mainw, NULL);
576 freewrlDrawArea = XtVaCreateManagedWidget (
"freewrlDrawArea", glwDrawingAreaWidgetClass,
577 frame,
"visualInfo", Xvi,
578 XmNtopAttachment, XmATTACH_WIDGET,
579 XmNbottomAttachment, XmATTACH_FORM,
580 XmNleftAttachment, XmATTACH_FORM,
581 XmNrightAttachment, XmATTACH_FORM,
585 freewrlDrawArea = XmCreateDrawingArea (frame,
"drawing_a", NULL, 0);
587 #ifdef DOESNOTGETICONICSTATE
588 XtAddCallback (freewrlDrawArea, XmNexposeCallback, fv_GLAreaexpose, NULL);
591 XtAddCallback (freewrlDrawArea, XmNresizeCallback, fv_GLArearesize, NULL);
593 myXtManageChild(27,freewrlDrawArea);
596 void setConsoleMessage (
char *str)
604 void frontendUpdateButtons()