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))
216 getPosition(&_dlgX, &_dlgY);
217 getSize(&_dlgW, &_dlgH);
218 _start_cursor = fgGetMouseCursor();
223 // check and prepare for resizing
224 static const int cursor[] = {
225 MOUSE_CURSOR_POINTER, MOUSE_CURSOR_LEFTSIDE, MOUSE_CURSOR_RIGHTSIDE, 0,
226 MOUSE_CURSOR_TOPSIDE, MOUSE_CURSOR_TOPLEFT, MOUSE_CURSOR_TOPRIGHT, 0,
227 MOUSE_CURSOR_BOTTOMSIDE, MOUSE_CURSOR_BOTTOMLEFT, MOUSE_CURSOR_BOTTOMRIGHT, 0,
231 int global_resize = fgGetKeyModifiers() & KEYMOD_CTRL;
232 int hmargin = global_resize ? _dlgW / 3 : 10;
233 int vmargin = global_resize ? _dlgH / 3 : 10;
235 if (y - _dlgY < vmargin)
237 else if (_dlgY + _dlgH - y < vmargin)
240 if (x - _dlgX < hmargin)
242 else if (_dlgX + _dlgW - x < hmargin)
245 if (!_resizing && global_resize)
246 _resizing = BOTTOM|RIGHT;
248 _cursor = cursor[_resizing];
249 if (_resizing && _resizable)
250 fgSetMouseCursor(_cursor);
252 } else if (updown == PU_DRAG && _dragging) {
257 GUIInfo *info = (GUIInfo *)getUserData();
258 if (info && info->node) {
262 LayoutWidget wid(info->node);
263 wid.calcPrefSize(&prefw, &prefh);
265 if (_resizing & LEFT)
267 if (_resizing & RIGHT)
271 if (_resizing & BOTTOM)
281 if (_resizing & LEFT)
283 if (_resizing & BOTTOM)
286 getFirstChild()->setSize(w, h); // dialog background puFrame
290 wid.layout(x, y, w, h);
291 applySize(static_cast<puObject *>(this));
294 setPosition(x + _dlgX - _startX, y + _dlgY - _startY);
299 fgSetMouseCursor(_start_cursor);
304 int fgPopup::getHitObjects(puObject *object, int x, int y)
306 if (!object->isVisible())
310 if (object->getType() & PUCLASS_GROUP)
311 for (puObject *obj = ((puGroup *)object)->getFirstChild();
312 obj; obj = obj->getNextObject())
313 type |= getHitObjects(obj, x, y);
316 object->getAbsolutePosition(&cx, &cy);
317 object->getSize(&cw, &ch);
318 if (x >= cx && x < cx + cw && y >= cy && y < cy + ch)
319 type |= object->getType();
323 void fgPopup::applySize(puObject *object)
325 // compound plib widgets use setUserData() for internal purposes, so refuse
326 // to descend into anything that has other bits set than the following
327 const int validUserData = PUCLASS_VALUE|PUCLASS_OBJECT|PUCLASS_GROUP|PUCLASS_INTERFACE
328 |PUCLASS_FRAME|PUCLASS_TEXT|PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
329 |PUCLASS_ARROW|PUCLASS_DIAL|PUCLASS_POPUP;
331 int type = object->getType();
332 if (type & PUCLASS_GROUP && !(type & ~validUserData))
333 for (puObject *obj = ((puGroup *)object)->getFirstChild();
334 obj; obj = obj->getNextObject())
337 GUIInfo *info = (GUIInfo *)object->getUserData();
341 SGPropertyNode *n = info->node;
343 SG_LOG(SG_GENERAL, SG_ALERT, "fgPopup::applySize: no props");
346 int x = n->getIntValue("x");
347 int y = n->getIntValue("y");
348 int w = n->getIntValue("width", 4);
349 int h = n->getIntValue("height", 4);
350 object->setPosition(x, y);
351 object->setSize(w, h);
355 ////////////////////////////////////////////////////////////////////////
357 ////////////////////////////////////////////////////////////////////////
363 action_callback (puObject * object)
365 GUIInfo * info = (GUIInfo *)object->getUserData();
366 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
367 gui->setActiveDialog(info->dialog);
368 int nBindings = info->bindings.size();
369 for (int i = 0; i < nBindings; i++) {
370 info->bindings[i]->fire();
371 if (gui->getActiveDialog() == 0)
374 gui->setActiveDialog(0);
379 ////////////////////////////////////////////////////////////////////////
380 // Static helper functions.
381 ////////////////////////////////////////////////////////////////////////
384 * Copy a property value to a PUI object.
387 copy_to_pui (SGPropertyNode * node, puObject * object)
389 GUIInfo *info = (GUIInfo *)object->getUserData();
391 SG_LOG(SG_GENERAL, SG_ALERT, "dialog: widget without GUIInfo!");
392 return; // this can't really happen
395 // Treat puText objects specially, so their "values" can be set
397 if (object->getType() & PUCLASS_TEXT) {
398 if (info->fmt_type != f_INVALID)
399 info->apply_format(node);
401 info->text = node->getStringValue();
403 object->setLabel(info->text.c_str());
407 switch (node->getType()) {
408 case SGPropertyNode::BOOL:
409 case SGPropertyNode::INT:
410 case SGPropertyNode::LONG:
411 object->setValue(node->getIntValue());
413 case SGPropertyNode::FLOAT:
414 case SGPropertyNode::DOUBLE:
415 object->setValue(node->getFloatValue());
418 info->text = node->getStringValue();
419 object->setValue(info->text.c_str());
426 copy_from_pui (puObject * object, SGPropertyNode * node)
428 // puText objects are immutable, so should not be copied out
429 if (object->getType() & PUCLASS_TEXT)
432 switch (node->getType()) {
433 case SGPropertyNode::BOOL:
434 case SGPropertyNode::INT:
435 case SGPropertyNode::LONG:
436 node->setIntValue(object->getIntegerValue());
438 case SGPropertyNode::FLOAT:
439 case SGPropertyNode::DOUBLE:
440 node->setFloatValue(object->getFloatValue());
443 const char *s = object->getStringValue();
445 node->setStringValue(s);
452 ////////////////////////////////////////////////////////////////////////
453 // Implementation of FGDialog.
454 ////////////////////////////////////////////////////////////////////////
456 FGDialog::FGDialog (SGPropertyNode * props)
458 _gui((NewGUI *)globals->get_subsystem("gui")),
461 _module = string("__dlg:") + props->getStringValue("name", "[unnamed]");
462 SGPropertyNode *nasal = props->getNode("nasal");
464 _nasal_close = nasal->getNode("close");
465 SGPropertyNode *open = nasal->getNode("open");
467 const char *s = open->getStringValue();
468 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
469 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), props);
475 FGDialog::~FGDialog ()
478 _object->getAbsolutePosition(&x, &y);
479 _props->setIntValue("lastx", x);
480 _props->setIntValue("lasty", y);
482 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
484 const char *s = _nasal_close->getStringValue();
485 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
487 nas->deleteModule(_module.c_str());
489 puDeleteObject(_object);
492 // Delete all the info objects we
493 // were forced to keep around because
494 // PUI cannot delete its own user data.
495 for (i = 0; i < _info.size(); i++) {
496 delete (GUIInfo *)_info[i];
499 // Finally, delete the property links.
500 for (i = 0; i < _propertyObjects.size(); i++) {
501 delete _propertyObjects[i];
502 _propertyObjects[i] = 0;
507 FGDialog::updateValues (const char * objectName)
509 if (objectName && !objectName[0])
512 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
513 const string &name = _propertyObjects[i]->name;
514 if (objectName && name != objectName)
517 puObject *obj = _propertyObjects[i]->object;
518 if ((obj->getType() & PUCLASS_LIST) && (dynamic_cast<GUI_ID *>(obj)->id & FGCLASS_LIST)) {
519 fgList *pl = static_cast<fgList *>(obj);
522 copy_to_pui(_propertyObjects[i]->node, obj);
527 FGDialog::applyValues (const char * objectName)
529 if (objectName && !objectName[0])
532 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
533 const string &name = _propertyObjects[i]->name;
534 if (objectName && name != objectName)
537 copy_from_pui(_propertyObjects[i]->object,
538 _propertyObjects[i]->node);
545 for (unsigned int i = 0; i < _liveObjects.size(); i++) {
546 puObject *obj = _liveObjects[i]->object;
547 if (obj->getType() & PUCLASS_INPUT && ((puInput *)obj)->isAcceptingInput())
550 copy_to_pui(_liveObjects[i]->node, obj);
555 FGDialog::display (SGPropertyNode * props)
558 SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
562 int screenw = globals->get_props()->getIntValue("/sim/startup/xsize");
563 int screenh = globals->get_props()->getIntValue("/sim/startup/ysize");
565 bool userx = props->hasValue("x");
566 bool usery = props->hasValue("y");
567 bool userw = props->hasValue("width");
568 bool userh = props->hasValue("height");
570 // Let the layout widget work in the same property subtree.
571 LayoutWidget wid(props);
573 SGPropertyNode *fontnode = props->getNode("font");
575 FGFontCache *fc = globals->get_fontcache();
576 _font = fc->get(fontnode);
578 _font = _gui->getDefaultFont();
580 wid.setDefaultFont(_font, int(_font->getPointSize()));
583 int px, py, savex, savey;
585 wid.calcPrefSize(&pw, &ph);
586 pw = props->getIntValue("width", pw);
587 ph = props->getIntValue("height", ph);
588 px = savex = props->getIntValue("x", (screenw - pw) / 2);
589 py = savey = props->getIntValue("y", (screenh - ph) / 2);
591 // Negative x/y coordinates are interpreted as distance from the top/right
592 // corner rather than bottom/left.
594 px = screenw - pw + px;
596 py = screenh - ph + py;
598 // Define "x", "y", "width" and/or "height" in the property tree if they
599 // are not specified in the configuration file.
600 wid.layout(px, py, pw, ph);
602 // Use the dimension and location properties as specified in the
603 // configuration file or from the layout widget.
604 _object = makeObject(props, screenw, screenh);
606 // Remove automatically generated properties, so the layout looks
607 // the same next time around, or restore x and y to preserve negative coords.
609 props->setIntValue("x", savex);
611 props->removeChild("x");
614 props->setIntValue("y", savey);
616 props->removeChild("y");
618 if(!userw) props->removeChild("width");
619 if(!userh) props->removeChild("height");
624 SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
625 << props->getStringValue("name", "[unnamed]")
626 << " does not contain a proper GUI definition");
631 FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
633 if (!props->getBoolValue("enabled", true))
636 bool presetSize = props->hasValue("width") && props->hasValue("height");
637 int width = props->getIntValue("width", parentWidth);
638 int height = props->getIntValue("height", parentHeight);
639 int x = props->getIntValue("x", (parentWidth - width) / 2);
640 int y = props->getIntValue("y", (parentHeight - height) / 2);
641 string type = props->getName();
646 if (type == "dialog") {
648 bool draggable = props->getBoolValue("draggable", true);
649 bool resizable = props->getBoolValue("resizable", false);
650 if (props->getBoolValue("modal", false))
651 obj = new puDialogBox(x, y);
653 obj = new fgPopup(x, y, resizable, draggable);
654 setupGroup(obj, props, width, height, true);
655 setColor(obj, props);
658 } else if (type == "group") {
659 puGroup * obj = new puGroup(x, y);
660 setupGroup(obj, props, width, height, false);
661 setColor(obj, props);
664 } else if (type == "frame") {
665 puGroup * obj = new puGroup(x, y);
666 setupGroup(obj, props, width, height, true);
667 setColor(obj, props);
670 } else if (type == "hrule" || type == "vrule") {
671 puFrame * obj = new puFrame(x, y, x + width, y + height);
672 obj->setBorderThickness(0);
673 setupObject(obj, props);
674 setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
677 } else if (type == "list") {
678 int slider_width = props->getIntValue("slider", 20);
679 fgList * obj = new fgList(x, y, x + width, y + height, props, slider_width);
681 obj->setSize(width, height);
682 setupObject(obj, props);
683 setColor(obj, props);
686 } else if (type == "airport-list") {
687 AirportList * obj = new AirportList(x, y, x + width, y + height);
689 obj->setSize(width, height);
690 setupObject(obj, props);
691 setColor(obj, props);
694 } else if (type == "property-list") {
695 PropertyList * obj = new PropertyList(x, y, x + width, y + height, globals->get_props());
697 obj->setSize(width, height);
698 setupObject(obj, props);
699 setColor(obj, props);
702 } else if (type == "input") {
703 puInput * obj = new puInput(x, y, x + width, y + height);
704 setupObject(obj, props);
705 setColor(obj, props, FOREGROUND|LABEL);
708 } else if (type == "text") {
709 puText * obj = new puText(x, y);
710 setupObject(obj, props);
712 // Layed-out objects need their size set, and non-layout ones
713 // get a different placement.
715 obj->setSize(width, height);
717 obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
718 setColor(obj, props, LABEL);
721 } else if (type == "checkbox") {
723 obj = new puButton(x, y, x + width, y + height, PUBUTTON_XCHECK);
724 setupObject(obj, props);
725 setColor(obj, props, FOREGROUND|LABEL);
728 } else if (type == "radio") {
730 obj = new puButton(x, y, x + width, y + height, PUBUTTON_CIRCLE);
731 setupObject(obj, props);
732 setColor(obj, props, FOREGROUND|LABEL);
735 } else if (type == "button") {
737 const char * legend = props->getStringValue("legend", "[none]");
738 if (props->getBoolValue("one-shot", true))
739 obj = new puOneShot(x, y, legend);
741 obj = new puButton(x, y, legend);
743 obj->setSize(width, height);
744 setupObject(obj, props);
745 setColor(obj, props);
748 } else if (type == "combo") {
749 fgComboBox * obj = new fgComboBox(x, y, x + width, y + height, props,
750 props->getBoolValue("editable", false));
751 setupObject(obj, props);
752 setColor(obj, props, EDITFIELD);
755 } else if (type == "slider") {
756 bool vertical = props->getBoolValue("vertical", false);
757 puSlider * obj = new puSlider(x, y, (vertical ? height : width));
758 obj->setMinValue(props->getFloatValue("min", 0.0));
759 obj->setMaxValue(props->getFloatValue("max", 1.0));
760 setupObject(obj, props);
762 obj->setSize(width, height);
763 setColor(obj, props, FOREGROUND|LABEL);
766 } else if (type == "dial") {
767 puDial * obj = new puDial(x, y, width);
768 obj->setMinValue(props->getFloatValue("min", 0.0));
769 obj->setMaxValue(props->getFloatValue("max", 1.0));
770 obj->setWrap(props->getBoolValue("wrap", true));
771 setupObject(obj, props);
772 setColor(obj, props, FOREGROUND|LABEL);
775 } else if (type == "textbox") {
776 int slider_width = props->getIntValue("slider", 20);
777 int wrap = props->getBoolValue("wrap", true);
778 puaLargeInput * obj = new puaLargeInput(x, y,
779 x+width, x+height, 2, slider_width, wrap);
781 if (props->hasValue("editable")) {
782 if (props->getBoolValue("editable")==false)
788 obj->setSize(width, height);
789 setupObject(obj, props);
790 setColor(obj, props, FOREGROUND|LABEL);
793 } else if (type == "select") {
794 fgSelectBox * obj = new fgSelectBox(x, y, x + width, y + height, props);
795 setupObject(obj, props);
796 setColor(obj, props, EDITFIELD);
804 FGDialog::setupObject (puObject * object, SGPropertyNode * props)
806 GUIInfo *info = new GUIInfo(this);
807 object->setUserData(info);
808 _info.push_back(info);
809 object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
810 object->makeReturnDefault(props->getBoolValue("default"));
813 if (props->hasValue("legend")) {
814 info->legend = props->getStringValue("legend");
815 object->setLegend(info->legend.c_str());
818 if (props->hasValue("label")) {
819 info->label = props->getStringValue("label");
820 object->setLabel(info->label.c_str());
823 if (props->hasValue("border"))
824 object->setBorderThickness( props->getIntValue("border", 2) );
826 if (SGPropertyNode *nft = props->getNode("font", false)) {
827 FGFontCache *fc = globals->get_fontcache();
828 puFont *lfnt = fc->get(nft);
829 object->setLabelFont(*lfnt);
830 object->setLegendFont(*lfnt);
832 object->setLabelFont(*_font);
835 if (props->hasValue("property")) {
836 const char * name = props->getStringValue("name");
839 const char * propname = props->getStringValue("property");
840 SGPropertyNode_ptr node = fgGetNode(propname, true);
841 copy_to_pui(node, object);
843 PropertyObject* po = new PropertyObject(name, object, node);
844 _propertyObjects.push_back(po);
845 if (props->getBoolValue("live"))
846 _liveObjects.push_back(po);
849 SGPropertyNode * dest = fgGetNode("/sim/bindings/gui", true);
850 vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
851 if (bindings.size() > 0) {
852 info->key = props->getIntValue("keynum", -1);
853 if (props->hasValue("key"))
854 info->key = getKeyCode(props->getStringValue("key", ""));
856 for (unsigned int i = 0; i < bindings.size(); i++) {
858 SGPropertyNode_ptr binding;
859 while (dest->getChild("binding", j))
862 const char *cmd = bindings[i]->getStringValue("command");
863 if (!strcmp(cmd, "nasal"))
864 bindings[i]->setStringValue("module", _module.c_str());
866 binding = dest->getChild("binding", j, true);
867 copyProperties(bindings[i], binding);
868 info->bindings.push_back(new SGBinding(binding, globals->get_props()));
870 object->setCallback(action_callback);
873 string type = props->getName();
874 if (type == "input" && props->getBoolValue("live"))
875 object->setDownCallback(action_callback);
877 if (type == "text") {
878 const char *format = props->getStringValue("format", 0);
880 info->fmt_type = validate_format(format);
881 if (info->fmt_type != f_INVALID)
882 info->format = format;
884 SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
891 FGDialog::setupGroup (puGroup * group, SGPropertyNode * props,
892 int width, int height, bool makeFrame)
894 setupObject(group, props);
897 puFrame* f = new puFrame(0, 0, width, height);
901 int nChildren = props->nChildren();
902 for (int i = 0; i < nChildren; i++)
903 makeObject(props->getChild(i), width, height);
908 FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
910 string type = props->getName();
913 if (type == "textbox" && props->getBoolValue("editable"))
916 FGColor c(_gui->getColor("background"));
917 c.merge(_gui->getColor(type));
918 c.merge(props->getNode("color"));
920 object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha());
928 { BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" },
929 { FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" },
930 { HIGHLIGHT, PUCOL_HIGHLIGHT, "highlight", "color-highlight" },
931 { LABEL, PUCOL_LABEL, "label", "color-label" },
932 { LEGEND, PUCOL_LEGEND, "legend", "color-legend" },
933 { MISC, PUCOL_MISC, "misc", "color-misc" },
934 { EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
937 const int numcol = sizeof(pucol) / sizeof(pucol[0]);
939 for (int i = 0; i < numcol; i++) {
944 dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name));
945 if (which & pucol[i].mask)
946 dirty |= c.merge(props->getNode("color"));
948 if ((pucol[i].mask == LABEL) && !c.isValid())
949 dirty |= c.merge(_gui->getColor("label"));
951 dirty |= c.merge(props->getNode(pucol[i].cname));
953 if (c.isValid() && dirty)
954 object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha());
986 {"left", PU_KEY_LEFT},
988 {"right", PU_KEY_RIGHT},
989 {"down", PU_KEY_DOWN},
990 {"pageup", PU_KEY_PAGE_UP},
991 {"pagedn", PU_KEY_PAGE_DOWN},
992 {"home", PU_KEY_HOME},
994 {"insert", PU_KEY_INSERT},
999 FGDialog::getKeyCode(const char *str)
1010 char *buf = new char[strlen(str) + 1];
1012 char *s = buf + strlen(buf);
1013 while (s > str && s[-1] == ' ')
1020 if (!strncmp(s, "Ctrl-", 5) || !strncmp(s, "CTRL-", 5))
1021 s += 5, mod |= CTRL;
1022 else if (!strncmp(s, "Shift-", 6) || !strncmp(s, "SHIFT-", 6))
1023 s += 6, mod |= SHIFT;
1024 else if (!strncmp(s, "Alt-", 4) || !strncmp(s, "ALT-", 4))
1031 if (strlen(s) == 1 && isascii(*s)) {
1036 key = toupper(key) - 64;
1038 ; // Alt not propagated to the gui
1040 for (char *t = s; *t; t++)
1042 for (int i = 0; keymap[i].name; i++) {
1043 if (!strcmp(s, keymap[i].name)) {
1044 key = keymap[i].key;
1055 ////////////////////////////////////////////////////////////////////////
1056 // Implementation of FGDialog::PropertyObject.
1057 ////////////////////////////////////////////////////////////////////////
1059 FGDialog::PropertyObject::PropertyObject (const char * n,
1061 SGPropertyNode_ptr p)
1071 ////////////////////////////////////////////////////////////////////////
1072 // Implementation of fgValueList and derived pui widgets
1073 ////////////////////////////////////////////////////////////////////////
1076 fgValueList::fgValueList(SGPropertyNode *p) :
1083 fgValueList::update()
1089 fgValueList::~fgValueList()
1095 fgValueList::make_list()
1097 vector<SGPropertyNode_ptr> value_nodes = _props->getChildren("value");
1098 _list = new char *[value_nodes.size() + 1];
1100 for (i = 0; i < value_nodes.size(); i++)
1101 _list[i] = strdup((char *)value_nodes[i]->getStringValue());
1106 fgValueList::destroy_list()
1108 for (int i = 0; _list[i] != 0; i++)
1119 fgValueList::update();
1120 int top = getTopItem();
1125 // end of dialog.cxx