1 // dialog.cxx: implementation of an XML-configurable dialog box.
7 #include <Input/input.hxx>
8 #include <Scripting/NasalSys.hxx>
9 #include <Main/fg_os.hxx>
12 #include "new_gui.hxx"
13 #include "AirportList.hxx"
14 #include "property_list.hxx"
18 enum format_type { f_INVALID, f_INT, f_LONG, f_FLOAT, f_DOUBLE, f_STRING };
19 static const int FORMAT_BUFSIZE = 255;
22 * Makes sure the format matches '%[ -+#]?\d*(\.\d*)?(l?[df]|s)', with
23 * only one number or string placeholder and otherwise arbitrary prefix
24 * and postfix containing only quoted percent signs (%%).
27 validate_format(const char *f)
41 while (*f == ' ' || *f == '+' || *f == '-' || *f == '#' || *f == '0')
43 while (*f && isdigit(*f))
47 while (*f && isdigit(*f))
55 type = l ? f_LONG : f_INT;
57 type = l ? f_DOUBLE : f_FLOAT;
77 ////////////////////////////////////////////////////////////////////////
78 // Implementation of GUIInfo.
79 ////////////////////////////////////////////////////////////////////////
82 * User data for a GUI object.
86 GUIInfo(FGDialog * d);
88 void apply_format(SGPropertyNode *);
91 SGPropertyNode_ptr node;
92 vector <SGBinding *> bindings;
94 string label, legend, text, format;
98 GUIInfo::GUIInfo (FGDialog * d) :
107 for (unsigned int i = 0; i < bindings.size(); i++) {
113 void GUIInfo::apply_format(SGPropertyNode *n)
115 char buf[FORMAT_BUFSIZE + 1];
116 if (fmt_type == f_INT)
117 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getIntValue());
118 else if (fmt_type == f_LONG)
119 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getLongValue());
120 else if (fmt_type == f_FLOAT)
121 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getFloatValue());
122 else if (fmt_type == f_DOUBLE)
123 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getDoubleValue());
125 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getStringValue());
127 buf[FORMAT_BUFSIZE] = '\0';
136 int fgPopup::checkKey(int key, int updown)
138 if (updown == PU_UP || !isVisible() || !isActive() || window != puGetWindow())
141 puObject *input = getActiveInputField(this);
143 return input->checkKey(key, updown);
145 puObject *object = getKeyObject(this, key);
147 return puPopup::checkKey(key, updown);
149 // invokeCallback() isn't enough; we need to simulate a mouse button press
150 object->checkHit(PU_LEFT_BUTTON, PU_DOWN,
151 (object->getABox()->min[0] + object->getABox()->max[0]) / 2,
152 (object->getABox()->min[1] + object->getABox()->max[1]) / 2);
153 object->checkHit(PU_LEFT_BUTTON, PU_UP,
154 (object->getABox()->min[0] + object->getABox()->max[0]) / 2,
155 (object->getABox()->min[1] + object->getABox()->max[1]) / 2);
159 puObject *fgPopup::getKeyObject(puObject *object, int key)
162 if (object->getType() & PUCLASS_GROUP)
163 for (puObject *obj = ((puGroup *)object)->getFirstChild();
164 obj; obj = obj->getNextObject())
165 if ((ret = getKeyObject(obj, key)))
168 GUIInfo *info = (GUIInfo *)object->getUserData();
169 if (info && info->key == key)
175 puObject *fgPopup::getActiveInputField(puObject *object)
178 if (object->getType() & PUCLASS_GROUP)
179 for (puObject *obj = ((puGroup *)object)->getFirstChild();
180 obj; obj = obj->getNextObject())
181 if ((ret = getActiveInputField(obj)))
184 if (object->getType() & PUCLASS_INPUT && ((puInput *)object)->isAcceptingInput())
193 int fgPopup::checkHit(int button, int updown, int x, int y)
196 if (updown != PU_DRAG && !_dragging)
197 result = puPopup::checkHit(button, updown, x, y);
202 // This is annoying. We would really want a true result from the
203 // superclass to indicate "handled by child object", but all it
204 // tells us is that the pointer is inside the dialog. So do the
205 // intersection test (again) to make sure we don't start a drag
206 // when inside controls.
208 if (updown == PU_DOWN && !_dragging) {
212 int hit = getHitObjects(this, x, y);
213 if (hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT|PUCLASS_LARGEINPUT))
214 return puPopup::checkHit(button, updown, x, y);
216 getPosition(&_dlgX, &_dlgY);
217 getSize(&_dlgW, &_dlgH);
218 _modifier = fgGetKeyModifiers();
223 } else if (updown == PU_DRAG && _dragging) {
224 if (_modifier & KEYMOD_CTRL) {
228 int w = _dlgW + x - _startX;
229 int h = _dlgH + _startY - y;
231 GUIInfo *info = (GUIInfo *)getUserData();
232 if (info && info->node) {
234 LayoutWidget wid(info->node);
235 wid.calcPrefSize(&pw, &ph);
240 int y = _dlgY + _dlgH - h;
242 // first child is always the dialog background puFrame
243 getFirstChild()->setSize(w, h);
245 setPosition(_dlgX, y);
247 wid.layout(_dlgX, y, w, h);
248 applySize(static_cast<puObject *>(this));
251 setPosition(x + _dlgX - _startX, y + _dlgY - _startY);
260 int fgPopup::getHitObjects(puObject *object, int x, int y)
262 if (!object->isVisible())
266 if (object->getType() & PUCLASS_GROUP)
267 for (puObject *obj = ((puGroup *)object)->getFirstChild();
268 obj; obj = obj->getNextObject())
269 type |= getHitObjects(obj, x, y);
272 object->getAbsolutePosition(&cx, &cy);
273 object->getSize(&cw, &ch);
274 if (x >= cx && x < cx + cw && y >= cy && y < cy + ch)
275 type |= object->getType();
279 void fgPopup::applySize(puObject *object)
281 // compound plib widgets use setUserData() for internal purposes, so refuse to
282 // descend into anything that has more bits set than the following
283 const int validUserData = PUCLASS_VALUE|PUCLASS_OBJECT|PUCLASS_GROUP|PUCLASS_INTERFACE
284 |PUCLASS_FRAME|PUCLASS_TEXT|PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
285 |PUCLASS_ARROW|PUCLASS_DIAL|PUCLASS_POPUP;
287 int type = object->getType();
288 if (type & PUCLASS_GROUP && !(type & ~validUserData))
289 for (puObject *obj = ((puGroup *)object)->getFirstChild();
290 obj; obj = obj->getNextObject())
293 GUIInfo *info = (GUIInfo *)object->getUserData();
297 SGPropertyNode *n = info->node;
299 SG_LOG(SG_GENERAL, SG_ALERT, "applySize: no props");
302 int x = n->getIntValue("x");
303 int y = n->getIntValue("y");
304 int w = n->getIntValue("width", 4);
305 int h = n->getIntValue("height", 4);
306 object->setPosition(x, y);
307 object->setSize(w, h);
311 ////////////////////////////////////////////////////////////////////////
313 ////////////////////////////////////////////////////////////////////////
319 action_callback (puObject * object)
321 GUIInfo * info = (GUIInfo *)object->getUserData();
322 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
323 gui->setActiveDialog(info->dialog);
324 int nBindings = info->bindings.size();
325 for (int i = 0; i < nBindings; i++) {
326 info->bindings[i]->fire();
327 if (gui->getActiveDialog() == 0)
330 gui->setActiveDialog(0);
335 ////////////////////////////////////////////////////////////////////////
336 // Static helper functions.
337 ////////////////////////////////////////////////////////////////////////
340 * Copy a property value to a PUI object.
343 copy_to_pui (SGPropertyNode * node, puObject * object)
345 GUIInfo *info = (GUIInfo *)object->getUserData();
347 SG_LOG(SG_GENERAL, SG_ALERT, "dialog: widget without GUIInfo!");
348 return; // this can't really happen
351 // Treat puText objects specially, so their "values" can be set
353 if (object->getType() & PUCLASS_TEXT) {
354 if (info->fmt_type != f_INVALID)
355 info->apply_format(node);
357 info->text = node->getStringValue();
359 object->setLabel(info->text.c_str());
363 switch (node->getType()) {
364 case SGPropertyNode::BOOL:
365 case SGPropertyNode::INT:
366 case SGPropertyNode::LONG:
367 object->setValue(node->getIntValue());
369 case SGPropertyNode::FLOAT:
370 case SGPropertyNode::DOUBLE:
371 object->setValue(node->getFloatValue());
374 info->text = node->getStringValue();
375 object->setValue(info->text.c_str());
382 copy_from_pui (puObject * object, SGPropertyNode * node)
384 // puText objects are immutable, so should not be copied out
385 if (object->getType() & PUCLASS_TEXT)
388 switch (node->getType()) {
389 case SGPropertyNode::BOOL:
390 case SGPropertyNode::INT:
391 case SGPropertyNode::LONG:
392 node->setIntValue(object->getIntegerValue());
394 case SGPropertyNode::FLOAT:
395 case SGPropertyNode::DOUBLE:
396 node->setFloatValue(object->getFloatValue());
399 const char *s = object->getStringValue();
401 node->setStringValue(s);
408 ////////////////////////////////////////////////////////////////////////
409 // Implementation of FGDialog.
410 ////////////////////////////////////////////////////////////////////////
412 FGDialog::FGDialog (SGPropertyNode * props)
414 _gui((NewGUI *)globals->get_subsystem("gui")),
417 _module = string("__dlg:") + props->getStringValue("name", "[unnamed]");
418 SGPropertyNode *nasal = props->getNode("nasal");
420 _nasal_close = nasal->getNode("close");
421 SGPropertyNode *open = nasal->getNode("open");
423 const char *s = open->getStringValue();
424 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
425 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), props);
431 FGDialog::~FGDialog ()
434 _object->getAbsolutePosition(&x, &y);
435 _props->setIntValue("lastx", x);
436 _props->setIntValue("lasty", y);
438 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
440 const char *s = _nasal_close->getStringValue();
441 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
443 nas->deleteModule(_module.c_str());
445 puDeleteObject(_object);
448 // Delete all the info objects we
449 // were forced to keep around because
450 // PUI cannot delete its own user data.
451 for (i = 0; i < _info.size(); i++) {
452 delete (GUIInfo *)_info[i];
455 // Finally, delete the property links.
456 for (i = 0; i < _propertyObjects.size(); i++) {
457 delete _propertyObjects[i];
458 _propertyObjects[i] = 0;
463 FGDialog::updateValues (const char * objectName)
465 if (objectName && !objectName[0])
468 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
469 const string &name = _propertyObjects[i]->name;
470 if (objectName && name != objectName)
473 puObject *obj = _propertyObjects[i]->object;
474 if ((obj->getType() & PUCLASS_LIST) && (dynamic_cast<GUI_ID *>(obj)->id & FGCLASS_LIST)) {
475 fgList *pl = static_cast<fgList *>(obj);
478 copy_to_pui(_propertyObjects[i]->node, obj);
483 FGDialog::applyValues (const char * objectName)
485 if (objectName && !objectName[0])
488 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
489 const string &name = _propertyObjects[i]->name;
490 if (objectName && name != objectName)
493 copy_from_pui(_propertyObjects[i]->object,
494 _propertyObjects[i]->node);
501 for (unsigned int i = 0; i < _liveObjects.size(); i++) {
502 puObject *obj = _liveObjects[i]->object;
503 if (obj->getType() & PUCLASS_INPUT && ((puInput *)obj)->isAcceptingInput())
506 copy_to_pui(_liveObjects[i]->node, obj);
511 FGDialog::display (SGPropertyNode * props)
514 SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
518 int screenw = globals->get_props()->getIntValue("/sim/startup/xsize");
519 int screenh = globals->get_props()->getIntValue("/sim/startup/ysize");
521 bool userx = props->hasValue("x");
522 bool usery = props->hasValue("y");
523 bool userw = props->hasValue("width");
524 bool userh = props->hasValue("height");
526 // Let the layout widget work in the same property subtree.
527 LayoutWidget wid(props);
529 SGPropertyNode *fontnode = props->getNode("font");
531 FGFontCache *fc = globals->get_fontcache();
532 _font = fc->get(fontnode);
534 _font = _gui->getDefaultFont();
536 wid.setDefaultFont(_font, int(_font->getPointSize()));
539 int px, py, savex, savey;
541 wid.calcPrefSize(&pw, &ph);
542 pw = props->getIntValue("width", pw);
543 ph = props->getIntValue("height", ph);
544 px = savex = props->getIntValue("x", (screenw - pw) / 2);
545 py = savey = props->getIntValue("y", (screenh - ph) / 2);
547 // Negative x/y coordinates are interpreted as distance from the top/right
548 // corner rather than bottom/left.
550 px = screenw - pw + px;
552 py = screenh - ph + py;
554 // Define "x", "y", "width" and/or "height" in the property tree if they
555 // are not specified in the configuration file.
556 wid.layout(px, py, pw, ph);
558 // Use the dimension and location properties as specified in the
559 // configuration file or from the layout widget.
560 _object = makeObject(props, screenw, screenh);
562 // Remove automatically generated properties, so the layout looks
563 // the same next time around, or restore x and y to preserve negative coords.
565 props->setIntValue("x", savex);
567 props->removeChild("x");
570 props->setIntValue("y", savey);
572 props->removeChild("y");
574 if(!userw) props->removeChild("width");
575 if(!userh) props->removeChild("height");
580 SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
581 << props->getStringValue("name", "[unnamed]")
582 << " does not contain a proper GUI definition");
587 FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
589 if (!props->getBoolValue("enabled", true))
592 bool presetSize = props->hasValue("width") && props->hasValue("height");
593 int width = props->getIntValue("width", parentWidth);
594 int height = props->getIntValue("height", parentHeight);
595 int x = props->getIntValue("x", (parentWidth - width) / 2);
596 int y = props->getIntValue("y", (parentHeight - height) / 2);
597 string type = props->getName();
602 if (type == "dialog") {
604 bool draggable = props->getBoolValue("draggable", true);
605 bool resizable = props->getBoolValue("resizable", false);
606 if (props->getBoolValue("modal", false))
607 obj = new puDialogBox(x, y);
609 obj = new fgPopup(x, y, resizable, draggable);
610 setupGroup(obj, props, width, height, true);
611 setColor(obj, props);
614 } else if (type == "group") {
615 puGroup * obj = new puGroup(x, y);
616 setupGroup(obj, props, width, height, false);
617 setColor(obj, props);
620 } else if (type == "frame") {
621 puGroup * obj = new puGroup(x, y);
622 setupGroup(obj, props, width, height, true);
623 setColor(obj, props);
626 } else if (type == "hrule" || type == "vrule") {
627 puFrame * obj = new puFrame(x, y, x + width, y + height);
628 obj->setBorderThickness(0);
629 setupObject(obj, props);
630 setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
633 } else if (type == "list") {
634 int slider_width = props->getIntValue("slider", 20);
635 fgList * obj = new fgList(x, y, x + width, y + height, props, slider_width);
637 obj->setSize(width, height);
638 setupObject(obj, props);
639 setColor(obj, props);
642 } else if (type == "airport-list") {
643 AirportList * obj = new AirportList(x, y, x + width, y + height);
645 obj->setSize(width, height);
646 setupObject(obj, props);
647 setColor(obj, props);
650 } else if (type == "property-list") {
651 PropertyList * obj = new PropertyList(x, y, x + width, y + height, globals->get_props());
653 obj->setSize(width, height);
654 setupObject(obj, props);
655 setColor(obj, props);
658 } else if (type == "input") {
659 puInput * obj = new puInput(x, y, x + width, y + height);
660 setupObject(obj, props);
661 setColor(obj, props, FOREGROUND|LABEL);
664 } else if (type == "text") {
665 puText * obj = new puText(x, y);
666 setupObject(obj, props);
668 // Layed-out objects need their size set, and non-layout ones
669 // get a different placement.
671 obj->setSize(width, height);
673 obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
674 setColor(obj, props, LABEL);
677 } else if (type == "checkbox") {
679 obj = new puButton(x, y, x + width, y + height, PUBUTTON_XCHECK);
680 setupObject(obj, props);
681 setColor(obj, props, FOREGROUND|LABEL);
684 } else if (type == "radio") {
686 obj = new puButton(x, y, x + width, y + height, PUBUTTON_CIRCLE);
687 setupObject(obj, props);
688 setColor(obj, props, FOREGROUND|LABEL);
691 } else if (type == "button") {
693 const char * legend = props->getStringValue("legend", "[none]");
694 if (props->getBoolValue("one-shot", true))
695 obj = new puOneShot(x, y, legend);
697 obj = new puButton(x, y, legend);
699 obj->setSize(width, height);
700 setupObject(obj, props);
701 setColor(obj, props);
704 } else if (type == "combo") {
705 fgComboBox * obj = new fgComboBox(x, y, x + width, y + height, props,
706 props->getBoolValue("editable", false));
707 setupObject(obj, props);
708 setColor(obj, props, EDITFIELD);
711 } else if (type == "slider") {
712 bool vertical = props->getBoolValue("vertical", false);
713 puSlider * obj = new puSlider(x, y, (vertical ? height : width));
714 obj->setMinValue(props->getFloatValue("min", 0.0));
715 obj->setMaxValue(props->getFloatValue("max", 1.0));
716 setupObject(obj, props);
718 obj->setSize(width, height);
719 setColor(obj, props, FOREGROUND|LABEL);
722 } else if (type == "dial") {
723 puDial * obj = new puDial(x, y, width);
724 obj->setMinValue(props->getFloatValue("min", 0.0));
725 obj->setMaxValue(props->getFloatValue("max", 1.0));
726 obj->setWrap(props->getBoolValue("wrap", true));
727 setupObject(obj, props);
728 setColor(obj, props, FOREGROUND|LABEL);
731 } else if (type == "textbox") {
732 int slider_width = props->getIntValue("slider", 20);
733 int wrap = props->getBoolValue("wrap", true);
734 puaLargeInput * obj = new puaLargeInput(x, y,
735 x+width, x+height, 2, slider_width, wrap);
737 if (props->hasValue("editable")) {
738 if (props->getBoolValue("editable")==false)
744 obj->setSize(width, height);
745 setupObject(obj, props);
746 setColor(obj, props, FOREGROUND|LABEL);
749 } else if (type == "select") {
750 fgSelectBox * obj = new fgSelectBox(x, y, x + width, y + height, props);
751 setupObject(obj, props);
752 setColor(obj, props, EDITFIELD);
760 FGDialog::setupObject (puObject * object, SGPropertyNode * props)
762 GUIInfo *info = new GUIInfo(this);
763 object->setUserData(info);
764 _info.push_back(info);
765 object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
766 object->makeReturnDefault(props->getBoolValue("default"));
769 if (props->hasValue("legend")) {
770 info->legend = props->getStringValue("legend");
771 object->setLegend(info->legend.c_str());
774 if (props->hasValue("label")) {
775 info->label = props->getStringValue("label");
776 object->setLabel(info->label.c_str());
779 if (props->hasValue("border"))
780 object->setBorderThickness( props->getIntValue("border", 2) );
782 if (SGPropertyNode *nft = props->getNode("font", false)) {
783 FGFontCache *fc = globals->get_fontcache();
784 puFont *lfnt = fc->get(nft);
785 object->setLabelFont(*lfnt);
786 object->setLegendFont(*lfnt);
788 object->setLabelFont(*_font);
791 if (props->hasValue("property")) {
792 const char * name = props->getStringValue("name");
795 const char * propname = props->getStringValue("property");
796 SGPropertyNode_ptr node = fgGetNode(propname, true);
797 copy_to_pui(node, object);
799 PropertyObject* po = new PropertyObject(name, object, node);
800 _propertyObjects.push_back(po);
801 if (props->getBoolValue("live"))
802 _liveObjects.push_back(po);
805 SGPropertyNode * dest = fgGetNode("/sim/bindings/gui", true);
806 vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
807 if (bindings.size() > 0) {
808 info->key = props->getIntValue("keynum", -1);
809 if (props->hasValue("key"))
810 info->key = getKeyCode(props->getStringValue("key", ""));
812 for (unsigned int i = 0; i < bindings.size(); i++) {
814 SGPropertyNode_ptr binding;
815 while (dest->getChild("binding", j))
818 const char *cmd = bindings[i]->getStringValue("command");
819 if (!strcmp(cmd, "nasal"))
820 bindings[i]->setStringValue("module", _module.c_str());
822 binding = dest->getChild("binding", j, true);
823 copyProperties(bindings[i], binding);
824 info->bindings.push_back(new SGBinding(binding, globals->get_props()));
826 object->setCallback(action_callback);
829 string type = props->getName();
830 if (type == "input" && props->getBoolValue("live"))
831 object->setDownCallback(action_callback);
833 if (type == "text") {
834 const char *format = props->getStringValue("format", 0);
836 info->fmt_type = validate_format(format);
837 if (info->fmt_type != f_INVALID)
838 info->format = format;
840 SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
847 FGDialog::setupGroup (puGroup * group, SGPropertyNode * props,
848 int width, int height, bool makeFrame)
850 setupObject(group, props);
853 puFrame* f = new puFrame(0, 0, width, height);
857 int nChildren = props->nChildren();
858 for (int i = 0; i < nChildren; i++)
859 makeObject(props->getChild(i), width, height);
864 FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
866 string type = props->getName();
869 if (type == "textbox" && props->getBoolValue("editable"))
872 FGColor c(_gui->getColor("background"));
873 c.merge(_gui->getColor(type));
874 c.merge(props->getNode("color"));
876 object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha());
884 { BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" },
885 { FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" },
886 { HIGHLIGHT, PUCOL_HIGHLIGHT, "highlight", "color-highlight" },
887 { LABEL, PUCOL_LABEL, "label", "color-label" },
888 { LEGEND, PUCOL_LEGEND, "legend", "color-legend" },
889 { MISC, PUCOL_MISC, "misc", "color-misc" },
890 { EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
893 const int numcol = sizeof(pucol) / sizeof(pucol[0]);
895 for (int i = 0; i < numcol; i++) {
900 dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name));
901 if (which & pucol[i].mask)
902 dirty |= c.merge(props->getNode("color"));
904 if ((pucol[i].mask == LABEL) && !c.isValid())
905 dirty |= c.merge(_gui->getColor("label"));
907 dirty |= c.merge(props->getNode(pucol[i].cname));
909 if (c.isValid() && dirty)
910 object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha());
942 {"left", PU_KEY_LEFT},
944 {"right", PU_KEY_RIGHT},
945 {"down", PU_KEY_DOWN},
946 {"pageup", PU_KEY_PAGE_UP},
947 {"pagedn", PU_KEY_PAGE_DOWN},
948 {"home", PU_KEY_HOME},
950 {"insert", PU_KEY_INSERT},
955 FGDialog::getKeyCode(const char *str)
966 char *buf = new char[strlen(str) + 1];
968 char *s = buf + strlen(buf);
969 while (s > str && s[-1] == ' ')
976 if (!strncmp(s, "Ctrl-", 5) || !strncmp(s, "CTRL-", 5))
978 else if (!strncmp(s, "Shift-", 6) || !strncmp(s, "SHIFT-", 6))
979 s += 6, mod |= SHIFT;
980 else if (!strncmp(s, "Alt-", 4) || !strncmp(s, "ALT-", 4))
987 if (strlen(s) == 1 && isascii(*s)) {
992 key = toupper(key) - 64;
994 ; // Alt not propagated to the gui
996 for (char *t = s; *t; t++)
998 for (int i = 0; keymap[i].name; i++) {
999 if (!strcmp(s, keymap[i].name)) {
1000 key = keymap[i].key;
1011 ////////////////////////////////////////////////////////////////////////
1012 // Implementation of FGDialog::PropertyObject.
1013 ////////////////////////////////////////////////////////////////////////
1015 FGDialog::PropertyObject::PropertyObject (const char * n,
1017 SGPropertyNode_ptr p)
1027 ////////////////////////////////////////////////////////////////////////
1028 // Implementation of fgValueList and derived pui widgets
1029 ////////////////////////////////////////////////////////////////////////
1032 fgValueList::fgValueList(SGPropertyNode *p) :
1039 fgValueList::update()
1045 fgValueList::~fgValueList()
1051 fgValueList::make_list()
1053 vector<SGPropertyNode_ptr> value_nodes = _props->getChildren("value");
1054 _list = new char *[value_nodes.size() + 1];
1056 for (i = 0; i < value_nodes.size(); i++)
1057 _list[i] = strdup((char *)value_nodes[i]->getStringValue());
1062 fgValueList::destroy_list()
1064 for (int i = 0; _list[i] != 0; i++)
1075 fgValueList::update();
1076 int top = getTopItem();
1081 // end of dialog.cxx