MenuBar::MenuBar ( Widget parent, char *name, unsigned char type ) : UIComponent ( name ) { // Base widget is a Motif menu bar widget if(parent == NULL) return; if( type == XmMENU_POPUP) { Arg args[1]; int i = 0; XtSetArg(args[i], XmNwhichButton, theApplication->bMenuButton()); i++; _w = XmCreatePopupMenu( parent, _name, args, i ); // XtVaSetValues(_w, XmNwhichButton, theApplication->bMenuButton(), NULL); } else { type = XmMENU_BAR; // Force it to menu bar _w = XmCreateMenuBar ( parent, _name, NULL, 0 ); } printHelpId("_w", _w); /* install callback */ // XtAddCallback(_w, XmNhelpCallback, HelpCB, helpId); installDestroyHandler(); }
Widget ViewMsgDialog::createWorkArea ( Widget shell ) { Widget form = XtCreateWidget( "Work_Area", xmFormWidgetClass, shell, NULL, 0); _main = XtVaCreateManagedWidget ("separateViewWindow", xmMainWindowWidgetClass, form, XmNleftAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); Widget form1 = XtCreateWidget("Work_Area", xmFormWidgetClass, _main, NULL, 0); printHelpId("form", form1); /* add help callback */ // XtAddCallback(form1, XmNhelpCallback, HelpCB, helpId); my_editor = new DtMailEditor(form1, this); my_editor->initialize(); my_editor->attachArea()->setOwnerShell(this); Widget wid = my_editor->container(); XtVaSetValues( wid, XmNrightAttachment,XmATTACH_FORM, XmNleftAttachment,XmATTACH_FORM, XmNtopAttachment,XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, NULL ); XtManageChild(form1); return form; }
// // Create the guts of the dialog // Widget FindDialog::createWorkArea(Widget dialog) { // TODO - CHECK ERROR!!! Widget *label = new Widget[_num_text_fields]; register unsigned int offset; _name = GETMSG(DT_catd, 1, 192, "Mailer - Find"); title(_name); // make this a modal dialog /* XtVaSetValues (dialog, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL); */ printHelpId("dialog", dialog); /* add help callback */ // XtAddCallback(dialog, XmNhelpCallback, HelpCB, helpId); Widget fd_pane = XtVaCreateWidget ("fd_pane", xmPanedWindowWidgetClass, dialog, XmNsashWidth, 1, XmNsashHeight, 1, NULL); printHelpId ("fd_pane", fd_pane); // add help callback // XtAddCallback (fd_pane, XmNhelpCallback, HelpCB, helpId); Widget fd_form = XtVaCreateWidget ("fd_form", xmFormWidgetClass, fd_pane, XmNfractionBase, 100, NULL); printHelpId ("fd_form", fd_form); // add help callback // XtAddCallback (fd_form, XmNhelpCallback, HelpCB, helpId); Widget _fd_labelbox = XtVaCreateManagedWidget ("_fd_labelbox", xmRowColumnWidgetClass, fd_form, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNrightAttachment, XmATTACH_POSITION, XmNleftPosition, 5, XmNrightPosition, 95, XmNpacking, XmPACK_COLUMN, XmNnumColumns, 2, XmNorientation, XmVERTICAL, XmNisAligned, True, XmNentryAlignment, XmALIGNMENT_END, XmNentryVerticalAlignment, XmALIGNMENT_CENTER, NULL); printHelpId ("_fd_labelbox", _fd_labelbox); // add help callback // XtAddCallback (_fd_labelbox, XmNhelpCallback, HelpCB, helpId); Widget *_fd_labels = new Widget [_num_text_fields]; int _fd_i = 0; for (_fd_i = 0; _fd_i < _num_text_fields; _fd_i++) { _fd_labels [_fd_i] = XtVaCreateManagedWidget ( _text_labels [_fd_i], xmLabelGadgetClass, _fd_labelbox, NULL); printHelpId ("_fd_labels [%s]", _fd_labels [_fd_i]); // naturally, this is bogus --must be fixed to return proper label // add help callback // XtAddCallback(_fd_labels [_fd_i], XmNhelpCallback, HelpCB, helpId); } for (_fd_i = 0; _fd_i < _num_text_fields; _fd_i++) { _text_fields [_fd_i] = XtVaCreateManagedWidget ( _text_names [_fd_i], xmTextFieldWidgetClass, _fd_labelbox, NULL); printHelpId ("_text_fields [%s]", _text_fields [_fd_i]); // naturally, this is bogus --must be fixed to return proper label // add help callback // XtAddCallback(_text_fields [_fd_i], XmNhelpCallback, HelpCB, helpId); XtAddCallback(_text_fields [_fd_i], XmNactivateCallback, (XtCallbackProc)textFieldCallback, (XtPointer)this); } XmString strForward = XmStringCreateLocalized(GETMSG(DT_catd, 1, 193, "Forward")); XmString strBackward = XmStringCreateLocalized(GETMSG(DT_catd, 1, 194, "Backward")); Widget fd_direction = XmVaCreateSimpleRadioBox(fd_form, "Direction", 0, // Initial selection directionCallback, //NULL, XmVaRADIOBUTTON, strForward, NULL, NULL, NULL, XmVaRADIOBUTTON, strBackward, NULL, NULL, NULL, XmNuserData, this, XmNsensitive, True, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, _fd_labelbox, XmNorientation, XmHORIZONTAL, XmNleftAttachment, XmATTACH_POSITION, XmNleftPosition, 33, NULL); printHelpId ("fd_direction", fd_direction); // add help callback //XtAddCallback (fd_direction, XmNhelpCallback, HelpCB, helpId); XmStringFree(strForward); XmStringFree(strBackward); // // Now create the Action Area. // #define TIGHTNESS 20 register Widget widget; Widget fd_action = XtVaCreateWidget("actionArea", xmFormWidgetClass, fd_pane, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNfractionBase, TIGHTNESS * _num_buttons-1, NULL); printHelpId ("actionArea", fd_action); // add help callback //XtAddCallback (fd_action, XmNhelpCallback, HelpCB, helpId); for (offset = 0; offset < _num_buttons; offset++) { widget = XtVaCreateManagedWidget(_buttonData[offset].label, xmPushButtonWidgetClass, fd_action, XmNleftAttachment, offset ? XmATTACH_POSITION:XmATTACH_FORM, XmNleftPosition, TIGHTNESS * offset, XmNtopAttachment, XmATTACH_FORM, XmNrightAttachment, offset != _num_buttons - 1 ? XmATTACH_POSITION : XmATTACH_FORM, XmNrightPosition, TIGHTNESS * offset + (TIGHTNESS - 1), XmNshowAsDefault, offset == 0, NULL); // again, bogus -- doesn't each one need a unique tag? printHelpId ("widget", widget); // add help callback //XtAddCallback (widget, XmNhelpCallback, HelpCB, helpId); if (_buttonData[offset].callback != NULL) { XtAddCallback(widget, XmNactivateCallback, _buttonData[offset].callback, _buttonData[offset].data); } if (offset == 0) { Dimension height; Dimension margin; XtVaGetValues(fd_action, XmNmarginHeight, &margin, NULL); XtVaGetValues(widget, XmNheight, &height, NULL); height +=2 * margin; XtVaSetValues(fd_action, XmNdefaultButton, widget, XmNpaneMaximum, height, XmNpaneMinimum, height, NULL); } } _status_text = XtVaCreateManagedWidget("StatusLabel", xmLabelWidgetClass, fd_pane, XmNrightAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNalignment, XmALIGNMENT_BEGINNING, NULL); Dimension height; XtWidgetGeometry size; size.request_mode = CWHeight; XtQueryGeometry(_status_text, NULL, &size); XtVaSetValues(_status_text, XmNpaneMaximum, size.height, XmNpaneMinimum, size.height, NULL); clearStatus(); XtManageChild (fd_form); XtManageChild (fd_direction); XtManageChild(fd_action); XtManageChild(fd_pane); XtManageChild(dialog); // Make sure get the height of the dialog after it has been // managed. XtVaGetValues(dialog, XmNheight, &height, NULL); XtVaSetValues(dialog, XmNmappedWhenManaged, True, XmNminHeight, height, NULL); XtRealizeWidget(dialog); return (fd_pane); }
Widget MenuBar::createPulldown ( Widget parent, CmdList *list, Boolean help , unsigned char type) { int i; Widget pulldown, cascade; Arg args2[2]; char * helpId; XmString label_str; if(type != XmMENU_POPUP) type = XmMENU_BAR; // Create a pulldown menu pane for this list of commands if( type == XmMENU_BAR) { pulldown = XmCreatePulldownMenu( parent, (char *) list->name(), NULL, 0 ); label_str = XmStringCreateLocalized(list->getLabel()); XtVaSetValues(pulldown, XmNlabelString, label_str, NULL); printHelpId("pulldown", pulldown); /* install callback */ // XtAddCallback(pulldown, XmNhelpCallback, HelpCB, helpId); // Each entry in the menu bar must have a cascade button // from which the user can pull down the pane XtSetArg(args2[0], XmNsubMenuId, pulldown); cascade = XtCreateWidget ( list->name(), xmCascadeButtonWidgetClass, parent, args2, 1); XtVaSetValues(cascade, XmNlabelString, label_str, NULL); if (help) { XtSetArg (args2[0], XmNmenuHelpWidget, cascade); XtSetValues (parent, args2, 1); } XtManageChild ( cascade ); printHelpId("cascade", cascade); /* install callback */ // Install callbacks for each of the // pulldown menus so we can get // On Item help for them. helpId = XtName(cascade); if (helpId == "Mailbox") { XtAddCallback(cascade, XmNhelpCallback, HelpCB, (void *)DTMAILCONTAINERMENUID); } else if (helpId == "Edit") { XtAddCallback(cascade, XmNhelpCallback, HelpCB, (void *)DTMAILEDITMENUID); } else if (helpId == "Message") { XtAddCallback(cascade, XmNhelpCallback, HelpCB, (void *)DTMAILMESSAGEMENUID); } else if (helpId == "Attachments") { XtAddCallback(cascade, XmNhelpCallback, HelpCB, (void *)DTMAILATTACHMENUID); } else if (helpId == "View") { XtAddCallback(cascade, XmNhelpCallback, HelpCB, (void *)DTMAILVIEWMENUID); } else if (helpId == "Compose") { XtAddCallback(cascade, XmNhelpCallback, HelpCB, (void *)DTMAILCOMPOSEMENUID); } } else pulldown = _w; // Loop through the cmdList, creating a menu // entry for each command. for ( i = 0; i < list->size(); i++) { if(!strcmp((*list)[i]->className(), "CmdList")) { Widget pane = createPulldown(pulldown, (CmdList*) (*list)[i], FALSE, XmMENU_BAR); ((CmdList *)(*list)[i])->setPaneWidget(pane); label_str = XmStringCreateLocalized((*list)[i]->getLabel()); XtVaSetValues(pane, XmNlabelString, label_str, NULL); } else { if ( !strcmp((*list)[i]->className(),"SeparatorCmd")) { XtCreateManagedWidget ( (*list)[i]->name(), xmSeparatorWidgetClass, pulldown, NULL, 0); } else if (!strcmp((*list)[i]->className(),"ToggleButtonCmd")) { CmdInterface *ci; ci = new ToggleButtonInterface(pulldown, (*list)[i]); ci->manage(); } else if(!strcmp((*list)[i]->className(),"LabelCmd")) { Widget _i18n; Arg _args[1]; XmString xms; _i18n = XtCreateManagedWidget( (*list)[i]->name(), xmLabelWidgetClass, pulldown, NULL, 0 ); xms = XmStringCreateLocalized((char*) (*list)[i]->getLabel()); XtSetArg( _args[0], XmNlabelString, xms ); XtSetValues( _i18n, _args, 1 ); XmStringFree(xms); } else { CmdInterface *ci; ci = new ButtonInterface ( pulldown, (*list)[i] ); ci->manage(); } } } return(pulldown); }
ToggleButtonInterface::ToggleButtonInterface ( Widget parent, Cmd *cmd ) : CmdInterface ( cmd ) { // We need to generate a button name that doesn't have illegal characters. // char *w_name = new char[200]; strcpy(w_name, _name); for (char * cur = w_name; *cur; cur++) { if (isspace(*cur) || *cur == ',') { *cur = '_'; continue; } if (*cur == '.') { *cur = 0; break; } } XmString label = XmStringCreateLocalized(cmd->getLabel()); if (0 == strcmp(cmd->className(),"ToggleButtonCmd")) { ToggleButtonCmd *tbc = (ToggleButtonCmd*) cmd; Boolean visible_when_off = tbc->visibleWhenOff(); unsigned char indicator_type = tbc->indicatorType(); _w = XtVaCreateWidget (w_name, xmToggleButtonWidgetClass, parent, XmNlabelString, label, XmNvisibleWhenOff, visible_when_off, XmNindicatorType, indicator_type, NULL); } else _w = XtVaCreateWidget (w_name, xmToggleButtonWidgetClass, parent, XmNlabelString, label, XmNvisibleWhenOff, TRUE, NULL); XmStringFree(label); printHelpId("_w", _w); // XtAddCallback(_w, XmNhelpCallback, HelpCB, helpId); // free(helpId); installDestroyHandler(); // The _active member is set when each instance is registered // with an associated Cmd object. Now that a widget exists, // set the widget's sensitivity according to its active state. if ( _active ) activate(); else deactivate(); #ifdef GNU_CC // No idea what the right ifdef is for automatically recognizing g++ // G++ reportedly doesn't like the form expected by cfront. I'm // told this will work, but I haven't tested it myself. XtAddCallback ( _w, XmNvalueChangedCallback, executeCmdCallback, (XtPointer) this ); #else XtAddCallback ( _w, XmNvalueChangedCallback, &CmdInterface::executeCmdCallback, (XtPointer) this ); #endif delete [] w_name; }