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.
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) {
211 int global_drag = fgGetKeyModifiers() & KEYMOD_SHIFT;
212 int global_resize = fgGetKeyModifiers() & KEYMOD_CTRL;
214 int hit = getHitObjects(this, x, y);
215 if (!global_resize && hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT|PUCLASS_LARGEINPUT))
218 getPosition(&_dlgX, &_dlgY);
219 getSize(&_dlgW, &_dlgH);
220 _start_cursor = fgGetMouseCursor();
225 // check and prepare for resizing
226 static const int cursor[] = {
227 MOUSE_CURSOR_POINTER, MOUSE_CURSOR_LEFTSIDE, MOUSE_CURSOR_RIGHTSIDE, 0,
228 MOUSE_CURSOR_TOPSIDE, MOUSE_CURSOR_TOPLEFT, MOUSE_CURSOR_TOPRIGHT, 0,
229 MOUSE_CURSOR_BOTTOMSIDE, MOUSE_CURSOR_BOTTOMLEFT, MOUSE_CURSOR_BOTTOMRIGHT, 0,
234 int hmargin = global_resize ? _dlgW / 3 : 10;
235 int vmargin = global_resize ? _dlgH / 3 : 10;
237 if (y - _dlgY < vmargin)
239 else if (_dlgY + _dlgH - y < vmargin)
242 if (x - _dlgX < hmargin)
244 else if (_dlgX + _dlgW - x < hmargin)
247 if (!_resizing && global_resize)
248 _resizing = BOTTOM|RIGHT;
250 _cursor = cursor[_resizing];
251 if (_resizing && _resizable)
252 fgSetMouseCursor(_cursor);
255 } else if (updown == PU_DRAG && _dragging) {
257 GUIInfo *info = (GUIInfo *)getUserData();
258 if (_resizable && info && info->node) {
261 if (_resizing & LEFT)
263 if (_resizing & RIGHT)
267 if (_resizing & BOTTOM)
271 LayoutWidget wid(info->node);
272 wid.calcPrefSize(&prefw, &prefh);
280 if (_resizing & LEFT)
282 if (_resizing & BOTTOM)
285 wid.layout(x, y, w, h);
288 applySize(static_cast<puObject *>(this));
289 getFirstChild()->setSize(w, h); // dialog background puFrame
292 setPosition(x + _dlgX - _startX, y + _dlgY - _startY);
295 } else if (_dragging) {
296 fgSetMouseCursor(_start_cursor);
302 int fgPopup::getHitObjects(puObject *object, int x, int y)
304 if (!object->isVisible())
308 if (object->getType() & PUCLASS_GROUP)
309 for (puObject *obj = ((puGroup *)object)->getFirstChild();
310 obj; obj = obj->getNextObject())
311 type |= getHitObjects(obj, x, y);
314 object->getAbsolutePosition(&cx, &cy);
315 object->getSize(&cw, &ch);
316 if (x >= cx && x < cx + cw && y >= cy && y < cy + ch)
317 type |= object->getType();
321 void fgPopup::applySize(puObject *object)
323 // compound plib widgets use setUserData() for internal purposes, so refuse
324 // to descend into anything that has other bits set than the following
325 const int validUserData = PUCLASS_VALUE|PUCLASS_OBJECT|PUCLASS_GROUP|PUCLASS_INTERFACE
326 |PUCLASS_FRAME|PUCLASS_TEXT|PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
327 |PUCLASS_ARROW|PUCLASS_DIAL|PUCLASS_POPUP;
329 int type = object->getType();
330 if (type & PUCLASS_GROUP && !(type & ~validUserData))
331 for (puObject *obj = ((puGroup *)object)->getFirstChild();
332 obj; obj = obj->getNextObject())
335 GUIInfo *info = (GUIInfo *)object->getUserData();
339 SGPropertyNode *n = info->node;
341 SG_LOG(SG_GENERAL, SG_ALERT, "fgPopup::applySize: no props");
344 int x = n->getIntValue("x");
345 int y = n->getIntValue("y");
346 int w = n->getIntValue("width", 4);
347 int h = n->getIntValue("height", 4);
348 object->setPosition(x, y);
349 object->setSize(w, h);
353 ////////////////////////////////////////////////////////////////////////
355 ////////////////////////////////////////////////////////////////////////
361 action_callback (puObject *object)
363 GUIInfo *info = (GUIInfo *)object->getUserData();
364 NewGUI *gui = (NewGUI *)globals->get_subsystem("gui");
365 gui->setActiveDialog(info->dialog);
366 int nBindings = info->bindings.size();
367 for (int i = 0; i < nBindings; i++) {
368 info->bindings[i]->fire();
369 if (gui->getActiveDialog() == 0)
372 gui->setActiveDialog(0);
377 ////////////////////////////////////////////////////////////////////////
378 // Static helper functions.
379 ////////////////////////////////////////////////////////////////////////
382 * Copy a property value to a PUI object.
385 copy_to_pui (SGPropertyNode *node, puObject *object)
387 GUIInfo *info = (GUIInfo *)object->getUserData();
389 SG_LOG(SG_GENERAL, SG_ALERT, "dialog: widget without GUIInfo!");
390 return; // this can't really happen
393 // Treat puText objects specially, so their "values" can be set
395 if (object->getType() & PUCLASS_TEXT) {
396 if (info->fmt_type != f_INVALID)
397 info->apply_format(node);
399 info->text = node->getStringValue();
401 object->setLabel(info->text.c_str());
405 switch (node->getType()) {
406 case SGPropertyNode::BOOL:
407 case SGPropertyNode::INT:
408 case SGPropertyNode::LONG:
409 object->setValue(node->getIntValue());
411 case SGPropertyNode::FLOAT:
412 case SGPropertyNode::DOUBLE:
413 object->setValue(node->getFloatValue());
416 info->text = node->getStringValue();
417 object->setValue(info->text.c_str());
424 copy_from_pui (puObject *object, SGPropertyNode *node)
426 // puText objects are immutable, so should not be copied out
427 if (object->getType() & PUCLASS_TEXT)
430 switch (node->getType()) {
431 case SGPropertyNode::BOOL:
432 case SGPropertyNode::INT:
433 case SGPropertyNode::LONG:
434 node->setIntValue(object->getIntegerValue());
436 case SGPropertyNode::FLOAT:
437 case SGPropertyNode::DOUBLE:
438 node->setFloatValue(object->getFloatValue());
441 const char *s = object->getStringValue();
443 node->setStringValue(s);
450 ////////////////////////////////////////////////////////////////////////
451 // Implementation of FGDialog.
452 ////////////////////////////////////////////////////////////////////////
454 FGDialog::FGDialog (SGPropertyNode *props) :
456 _gui((NewGUI *)globals->get_subsystem("gui")),
459 _module = string("__dlg:") + props->getStringValue("name", "[unnamed]");
460 SGPropertyNode *nasal = props->getNode("nasal");
462 _nasal_close = nasal->getNode("close");
463 SGPropertyNode *open = nasal->getNode("open");
465 const char *s = open->getStringValue();
466 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
467 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), props);
473 FGDialog::~FGDialog ()
476 _object->getAbsolutePosition(&x, &y);
477 _props->setIntValue("lastx", x);
478 _props->setIntValue("lasty", y);
480 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
482 const char *s = _nasal_close->getStringValue();
483 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
485 nas->deleteModule(_module.c_str());
487 puDeleteObject(_object);
490 // Delete all the info objects we
491 // were forced to keep around because
492 // PUI cannot delete its own user data.
493 for (i = 0; i < _info.size(); i++) {
494 delete (GUIInfo *)_info[i];
497 // Finally, delete the property links.
498 for (i = 0; i < _propertyObjects.size(); i++) {
499 delete _propertyObjects[i];
500 _propertyObjects[i] = 0;
505 FGDialog::updateValues (const char *objectName)
507 if (objectName && !objectName[0])
510 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
511 const string &name = _propertyObjects[i]->name;
512 if (objectName && name != objectName)
515 puObject *obj = _propertyObjects[i]->object;
516 if ((obj->getType() & PUCLASS_LIST) && (dynamic_cast<GUI_ID *>(obj)->id & FGCLASS_LIST)) {
517 fgList *pl = static_cast<fgList *>(obj);
520 copy_to_pui(_propertyObjects[i]->node, obj);
525 FGDialog::applyValues (const char *objectName)
527 if (objectName && !objectName[0])
530 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
531 const string &name = _propertyObjects[i]->name;
532 if (objectName && name != objectName)
535 copy_from_pui(_propertyObjects[i]->object,
536 _propertyObjects[i]->node);
543 for (unsigned int i = 0; i < _liveObjects.size(); i++) {
544 puObject *obj = _liveObjects[i]->object;
545 if (obj->getType() & PUCLASS_INPUT && ((puInput *)obj)->isAcceptingInput())
548 copy_to_pui(_liveObjects[i]->node, obj);
553 FGDialog::display (SGPropertyNode *props)
556 SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
560 int screenw = globals->get_props()->getIntValue("/sim/startup/xsize");
561 int screenh = globals->get_props()->getIntValue("/sim/startup/ysize");
563 bool userx = props->hasValue("x");
564 bool usery = props->hasValue("y");
565 bool userw = props->hasValue("width");
566 bool userh = props->hasValue("height");
568 // Let the layout widget work in the same property subtree.
569 LayoutWidget wid(props);
571 SGPropertyNode *fontnode = props->getNode("font");
573 FGFontCache *fc = globals->get_fontcache();
574 _font = fc->get(fontnode);
576 _font = _gui->getDefaultFont();
578 wid.setDefaultFont(_font, int(_font->getPointSize()));
581 int px, py, savex, savey;
582 if (!userw || !userh)
583 wid.calcPrefSize(&pw, &ph);
584 pw = props->getIntValue("width", pw);
585 ph = props->getIntValue("height", ph);
586 px = savex = props->getIntValue("x", (screenw - pw) / 2);
587 py = savey = props->getIntValue("y", (screenh - ph) / 2);
589 // Negative x/y coordinates are interpreted as distance from the top/right
590 // corner rather than bottom/left.
592 px = screenw - pw + px;
594 py = screenh - ph + py;
596 // Define "x", "y", "width" and/or "height" in the property tree if they
597 // are not specified in the configuration file.
598 wid.layout(px, py, pw, ph);
600 // Use the dimension and location properties as specified in the
601 // configuration file or from the layout widget.
602 _object = makeObject(props, screenw, screenh);
604 // Remove automatically generated properties, so the layout looks
605 // the same next time around, or restore x and y to preserve negative coords.
607 props->setIntValue("x", savex);
609 props->removeChild("x");
612 props->setIntValue("y", savey);
614 props->removeChild("y");
616 if (!userw) props->removeChild("width");
617 if (!userh) props->removeChild("height");
622 SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
623 << props->getStringValue("name", "[unnamed]")
624 << " does not contain a proper GUI definition");
629 FGDialog::makeObject (SGPropertyNode *props, int parentWidth, int parentHeight)
631 if (!props->getBoolValue("enabled", true))
634 bool presetSize = props->hasValue("width") && props->hasValue("height");
635 int width = props->getIntValue("width", parentWidth);
636 int height = props->getIntValue("height", parentHeight);
637 int x = props->getIntValue("x", (parentWidth - width) / 2);
638 int y = props->getIntValue("y", (parentHeight - height) / 2);
639 string type = props->getName();
644 if (type == "dialog") {
646 bool draggable = props->getBoolValue("draggable", true);
647 bool resizable = props->getBoolValue("resizable", false);
648 if (props->getBoolValue("modal", false))
649 obj = new puDialogBox(x, y);
651 obj = new fgPopup(x, y, resizable, draggable);
652 setupGroup(obj, props, width, height, true);
653 setColor(obj, props);
656 } else if (type == "group") {
657 puGroup *obj = new puGroup(x, y);
658 setupGroup(obj, props, width, height, false);
659 setColor(obj, props);
662 } else if (type == "frame") {
663 puGroup *obj = new puGroup(x, y);
664 setupGroup(obj, props, width, height, true);
665 setColor(obj, props);
668 } else if (type == "hrule" || type == "vrule") {
669 puFrame *obj = new puFrame(x, y, x + width, y + height);
670 obj->setBorderThickness(0);
671 setupObject(obj, props);
672 setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
675 } else if (type == "list") {
676 int slider_width = props->getIntValue("slider", 20);
677 fgList *obj = new fgList(x, y, x + width, y + height, props, slider_width);
679 obj->setSize(width, height);
680 setupObject(obj, props);
681 setColor(obj, props);
684 } else if (type == "airport-list") {
685 AirportList *obj = new AirportList(x, y, x + width, y + height);
687 obj->setSize(width, height);
688 setupObject(obj, props);
689 setColor(obj, props);
692 } else if (type == "property-list") {
693 PropertyList *obj = new PropertyList(x, y, x + width, y + height, globals->get_props());
695 obj->setSize(width, height);
696 setupObject(obj, props);
697 setColor(obj, props);
700 } else if (type == "input") {
701 puInput *obj = new puInput(x, y, x + width, y + height);
702 setupObject(obj, props);
703 setColor(obj, props, FOREGROUND|LABEL);
706 } else if (type == "text") {
707 puText *obj = new puText(x, y);
708 setupObject(obj, props);
710 // Layed-out objects need their size set, and non-layout ones
711 // get a different placement.
713 obj->setSize(width, height);
715 obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
716 setColor(obj, props, LABEL);
719 } else if (type == "checkbox") {
721 obj = new puButton(x, y, x + width, y + height, PUBUTTON_XCHECK);
722 setupObject(obj, props);
723 setColor(obj, props, FOREGROUND|LABEL);
726 } else if (type == "radio") {
728 obj = new puButton(x, y, x + width, y + height, PUBUTTON_CIRCLE);
729 setupObject(obj, props);
730 setColor(obj, props, FOREGROUND|LABEL);
733 } else if (type == "button") {
735 const char *legend = props->getStringValue("legend", "[none]");
736 if (props->getBoolValue("one-shot", true))
737 obj = new puOneShot(x, y, legend);
739 obj = new puButton(x, y, legend);
741 obj->setSize(width, height);
742 setupObject(obj, props);
743 setColor(obj, props);
746 } else if (type == "combo") {
747 fgComboBox *obj = new fgComboBox(x, y, x + width, y + height, props,
748 props->getBoolValue("editable", false));
749 setupObject(obj, props);
750 setColor(obj, props, EDITFIELD);
753 } else if (type == "slider") {
754 bool vertical = props->getBoolValue("vertical", false);
755 puSlider *obj = new puSlider(x, y, (vertical ? height : width));
756 obj->setMinValue(props->getFloatValue("min", 0.0));
757 obj->setMaxValue(props->getFloatValue("max", 1.0));
758 setupObject(obj, props);
760 obj->setSize(width, height);
761 setColor(obj, props, FOREGROUND|LABEL);
764 } else if (type == "dial") {
765 puDial *obj = new puDial(x, y, width);
766 obj->setMinValue(props->getFloatValue("min", 0.0));
767 obj->setMaxValue(props->getFloatValue("max", 1.0));
768 obj->setWrap(props->getBoolValue("wrap", true));
769 setupObject(obj, props);
770 setColor(obj, props, FOREGROUND|LABEL);
773 } else if (type == "textbox") {
774 int slider_width = props->getIntValue("slider", 20);
775 int wrap = props->getBoolValue("wrap", true);
776 puaLargeInput * obj = new puaLargeInput(x, y,
777 x + width, x + height, 2, slider_width, wrap);
779 if (props->hasValue("editable")) {
780 if (props->getBoolValue("editable")==false)
786 obj->setSize(width, height);
787 setupObject(obj, props);
788 setColor(obj, props, FOREGROUND|LABEL);
791 } else if (type == "select") {
792 fgSelectBox *obj = new fgSelectBox(x, y, x + width, y + height, props);
793 setupObject(obj, props);
794 setColor(obj, props, EDITFIELD);
802 FGDialog::setupObject (puObject *object, SGPropertyNode *props)
804 GUIInfo *info = new GUIInfo(this);
805 object->setUserData(info);
806 _info.push_back(info);
807 object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
808 object->makeReturnDefault(props->getBoolValue("default"));
811 if (props->hasValue("legend")) {
812 info->legend = props->getStringValue("legend");
813 object->setLegend(info->legend.c_str());
816 if (props->hasValue("label")) {
817 info->label = props->getStringValue("label");
818 object->setLabel(info->label.c_str());
821 if (props->hasValue("border"))
822 object->setBorderThickness( props->getIntValue("border", 2) );
824 if (SGPropertyNode *nft = props->getNode("font", false)) {
825 FGFontCache *fc = globals->get_fontcache();
826 puFont *lfnt = fc->get(nft);
827 object->setLabelFont(*lfnt);
828 object->setLegendFont(*lfnt);
830 object->setLabelFont(*_font);
833 if (props->hasValue("property")) {
834 const char *name = props->getStringValue("name");
837 const char *propname = props->getStringValue("property");
838 SGPropertyNode_ptr node = fgGetNode(propname, true);
839 copy_to_pui(node, object);
841 PropertyObject *po = new PropertyObject(name, object, node);
842 _propertyObjects.push_back(po);
843 if (props->getBoolValue("live"))
844 _liveObjects.push_back(po);
847 SGPropertyNode *dest = fgGetNode("/sim/bindings/gui", true);
848 vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
849 if (bindings.size() > 0) {
850 info->key = props->getIntValue("keynum", -1);
851 if (props->hasValue("key"))
852 info->key = getKeyCode(props->getStringValue("key", ""));
854 for (unsigned int i = 0; i < bindings.size(); i++) {
856 SGPropertyNode_ptr binding;
857 while (dest->getChild("binding", j))
860 const char *cmd = bindings[i]->getStringValue("command");
861 if (!strcmp(cmd, "nasal"))
862 bindings[i]->setStringValue("module", _module.c_str());
864 binding = dest->getChild("binding", j, true);
865 copyProperties(bindings[i], binding);
866 info->bindings.push_back(new SGBinding(binding, globals->get_props()));
868 object->setCallback(action_callback);
871 string type = props->getName();
872 if (type == "input" && props->getBoolValue("live"))
873 object->setDownCallback(action_callback);
875 if (type == "text") {
876 const char *format = props->getStringValue("format", 0);
878 info->fmt_type = validate_format(format);
879 if (info->fmt_type != f_INVALID)
880 info->format = format;
882 SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
889 FGDialog::setupGroup(puGroup *group, SGPropertyNode *props,
890 int width, int height, bool makeFrame)
892 setupObject(group, props);
895 puFrame* f = new puFrame(0, 0, width, height);
899 int nChildren = props->nChildren();
900 for (int i = 0; i < nChildren; i++)
901 makeObject(props->getChild(i), width, height);
906 FGDialog::setColor(puObject *object, SGPropertyNode *props, int which)
908 string type = props->getName();
911 if (type == "textbox" && props->getBoolValue("editable"))
914 FGColor c(_gui->getColor("background"));
915 c.merge(_gui->getColor(type));
916 c.merge(props->getNode("color"));
918 object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha());
926 { BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" },
927 { FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" },
928 { HIGHLIGHT, PUCOL_HIGHLIGHT, "highlight", "color-highlight" },
929 { LABEL, PUCOL_LABEL, "label", "color-label" },
930 { LEGEND, PUCOL_LEGEND, "legend", "color-legend" },
931 { MISC, PUCOL_MISC, "misc", "color-misc" },
932 { EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
935 const int numcol = sizeof(pucol) / sizeof(pucol[0]);
937 for (int i = 0; i < numcol; i++) {
942 dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name));
943 if (which & pucol[i].mask)
944 dirty |= c.merge(props->getNode("color"));
946 if ((pucol[i].mask == LABEL) && !c.isValid())
947 dirty |= c.merge(_gui->getColor("label"));
949 dirty |= c.merge(props->getNode(pucol[i].cname));
951 if (c.isValid() && dirty)
952 object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha());
984 {"left", PU_KEY_LEFT},
986 {"right", PU_KEY_RIGHT},
987 {"down", PU_KEY_DOWN},
988 {"pageup", PU_KEY_PAGE_UP},
989 {"pagedn", PU_KEY_PAGE_DOWN},
990 {"home", PU_KEY_HOME},
992 {"insert", PU_KEY_INSERT},
997 FGDialog::getKeyCode(const char *str)
1008 char *buf = new char[strlen(str) + 1];
1010 char *s = buf + strlen(buf);
1011 while (s > str && s[-1] == ' ')
1018 if (!strncmp(s, "Ctrl-", 5) || !strncmp(s, "CTRL-", 5))
1019 s += 5, mod |= CTRL;
1020 else if (!strncmp(s, "Shift-", 6) || !strncmp(s, "SHIFT-", 6))
1021 s += 6, mod |= SHIFT;
1022 else if (!strncmp(s, "Alt-", 4) || !strncmp(s, "ALT-", 4))
1029 if (strlen(s) == 1 && isascii(*s)) {
1034 key = toupper(key) - '@';
1036 ; // Alt not propagated to the gui
1038 for (char *t = s; *t; t++)
1040 for (int i = 0; keymap[i].name; i++) {
1041 if (!strcmp(s, keymap[i].name)) {
1042 key = keymap[i].key;
1053 ////////////////////////////////////////////////////////////////////////
1054 // Implementation of FGDialog::PropertyObject.
1055 ////////////////////////////////////////////////////////////////////////
1057 FGDialog::PropertyObject::PropertyObject(const char *n,
1058 puObject *o, SGPropertyNode_ptr p) :
1068 ////////////////////////////////////////////////////////////////////////
1069 // Implementation of fgValueList and derived pui widgets
1070 ////////////////////////////////////////////////////////////////////////
1073 fgValueList::fgValueList(SGPropertyNode *p) :
1080 fgValueList::update()
1086 fgValueList::~fgValueList()
1092 fgValueList::make_list()
1094 vector<SGPropertyNode_ptr> value_nodes = _props->getChildren("value");
1095 _list = new char *[value_nodes.size() + 1];
1097 for (i = 0; i < value_nodes.size(); i++)
1098 _list[i] = strdup((char *)value_nodes[i]->getStringValue());
1103 fgValueList::destroy_list()
1105 for (int i = 0; _list[i] != 0; i++)
1116 fgValueList::update();
1117 int top = getTopItem();
1122 // end of dialog.cxx