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 (hit & PUCLASS_LIST) // ctrl-click in property browser (toggle bool)
217 if (!global_resize && hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT|PUCLASS_LARGEINPUT))
220 getPosition(&_dlgX, &_dlgY);
221 getSize(&_dlgW, &_dlgH);
222 _start_cursor = fgGetMouseCursor();
227 // check and prepare for resizing
228 static const int cursor[] = {
229 MOUSE_CURSOR_POINTER, MOUSE_CURSOR_LEFTSIDE, MOUSE_CURSOR_RIGHTSIDE, 0,
230 MOUSE_CURSOR_TOPSIDE, MOUSE_CURSOR_TOPLEFT, MOUSE_CURSOR_TOPRIGHT, 0,
231 MOUSE_CURSOR_BOTTOMSIDE, MOUSE_CURSOR_BOTTOMLEFT, MOUSE_CURSOR_BOTTOMRIGHT, 0,
235 if (!global_drag && _resizable) {
236 int hmargin = global_resize ? _dlgW / 3 : 10;
237 int vmargin = global_resize ? _dlgH / 3 : 10;
239 if (y - _dlgY < vmargin)
241 else if (_dlgY + _dlgH - y < vmargin)
244 if (x - _dlgX < hmargin)
246 else if (_dlgX + _dlgW - x < hmargin)
249 if (!_resizing && global_resize)
250 _resizing = BOTTOM|RIGHT;
252 _cursor = cursor[_resizing];
253 if (_resizing && _resizable)
254 fgSetMouseCursor(_cursor);
257 } else if (updown == PU_DRAG && _dragging) {
259 GUIInfo *info = (GUIInfo *)getUserData();
260 if (_resizable && info && info->node) {
263 if (_resizing & LEFT)
265 if (_resizing & RIGHT)
269 if (_resizing & BOTTOM)
273 LayoutWidget wid(info->node);
274 wid.calcPrefSize(&prefw, &prefh);
282 if (_resizing & LEFT)
284 if (_resizing & BOTTOM)
287 wid.layout(x, y, w, h);
290 applySize(static_cast<puObject *>(this));
291 getFirstChild()->setSize(w, h); // dialog background puFrame
294 setPosition(x + _dlgX - _startX, y + _dlgY - _startY);
297 } else if (_dragging) {
298 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;
584 if (!userw || !userh)
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), vertical);
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->getBoolValue("editable"))
787 obj->setSize(width, height);
788 setupObject(obj, props);
789 setColor(obj, props, FOREGROUND|LABEL);
792 } else if (type == "select") {
793 fgSelectBox *obj = new fgSelectBox(x, y, x + width, y + height, props);
794 setupObject(obj, props);
795 setColor(obj, props, EDITFIELD);
803 FGDialog::setupObject (puObject *object, SGPropertyNode *props)
805 GUIInfo *info = new GUIInfo(this);
806 object->setUserData(info);
807 _info.push_back(info);
808 object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
809 object->makeReturnDefault(props->getBoolValue("default"));
812 if (props->hasValue("legend")) {
813 info->legend = props->getStringValue("legend");
814 object->setLegend(info->legend.c_str());
817 if (props->hasValue("label")) {
818 info->label = props->getStringValue("label");
819 object->setLabel(info->label.c_str());
822 if (props->hasValue("border"))
823 object->setBorderThickness( props->getIntValue("border", 2) );
825 if (SGPropertyNode *nft = props->getNode("font", false)) {
826 FGFontCache *fc = globals->get_fontcache();
827 puFont *lfnt = fc->get(nft);
828 object->setLabelFont(*lfnt);
829 object->setLegendFont(*lfnt);
831 object->setLabelFont(*_font);
834 if (props->hasValue("property")) {
835 const char *name = props->getStringValue("name");
838 const char *propname = props->getStringValue("property");
839 SGPropertyNode_ptr node = fgGetNode(propname, true);
840 copy_to_pui(node, object);
842 PropertyObject *po = new PropertyObject(name, object, node);
843 _propertyObjects.push_back(po);
844 if (props->getBoolValue("live"))
845 _liveObjects.push_back(po);
848 SGPropertyNode *dest = fgGetNode("/sim/bindings/gui", true);
849 vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
850 if (bindings.size() > 0) {
851 info->key = props->getIntValue("keynum", -1);
852 if (props->hasValue("key"))
853 info->key = getKeyCode(props->getStringValue("key", ""));
855 for (unsigned int i = 0; i < bindings.size(); i++) {
857 SGPropertyNode_ptr binding;
858 while (dest->getChild("binding", j))
861 const char *cmd = bindings[i]->getStringValue("command");
862 if (!strcmp(cmd, "nasal"))
863 bindings[i]->setStringValue("module", _module.c_str());
865 binding = dest->getChild("binding", j, true);
866 copyProperties(bindings[i], binding);
867 info->bindings.push_back(new SGBinding(binding, globals->get_props()));
869 object->setCallback(action_callback);
872 string type = props->getName();
873 if (type == "input" && props->getBoolValue("live"))
874 object->setDownCallback(action_callback);
876 if (type == "text") {
877 const char *format = props->getStringValue("format", 0);
879 info->fmt_type = validate_format(format);
880 if (info->fmt_type != f_INVALID)
881 info->format = format;
883 SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
890 FGDialog::setupGroup(puGroup *group, SGPropertyNode *props,
891 int width, int height, bool makeFrame)
893 setupObject(group, props);
896 puFrame* f = new puFrame(0, 0, width, height);
900 int nChildren = props->nChildren();
901 for (int i = 0; i < nChildren; i++)
902 makeObject(props->getChild(i), width, height);
907 FGDialog::setColor(puObject *object, SGPropertyNode *props, int which)
909 string type = props->getName();
912 if (type == "textbox" && props->getBoolValue("editable"))
915 FGColor c(_gui->getColor("background"));
916 c.merge(_gui->getColor(type));
917 c.merge(props->getNode("color"));
919 object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha());
927 { BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" },
928 { FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" },
929 { HIGHLIGHT, PUCOL_HIGHLIGHT, "highlight", "color-highlight" },
930 { LABEL, PUCOL_LABEL, "label", "color-label" },
931 { LEGEND, PUCOL_LEGEND, "legend", "color-legend" },
932 { MISC, PUCOL_MISC, "misc", "color-misc" },
933 { EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
936 const int numcol = sizeof(pucol) / sizeof(pucol[0]);
938 for (int i = 0; i < numcol; i++) {
943 dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name));
944 if (which & pucol[i].mask)
945 dirty |= c.merge(props->getNode("color"));
947 if ((pucol[i].mask == LABEL) && !c.isValid())
948 dirty |= c.merge(_gui->getColor("label"));
950 dirty |= c.merge(props->getNode(pucol[i].cname));
952 if (c.isValid() && dirty)
953 object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha());
985 {"left", PU_KEY_LEFT},
987 {"right", PU_KEY_RIGHT},
988 {"down", PU_KEY_DOWN},
989 {"pageup", PU_KEY_PAGE_UP},
990 {"pagedn", PU_KEY_PAGE_DOWN},
991 {"home", PU_KEY_HOME},
993 {"insert", PU_KEY_INSERT},
998 FGDialog::getKeyCode(const char *str)
1009 char *buf = new char[strlen(str) + 1];
1011 char *s = buf + strlen(buf);
1012 while (s > str && s[-1] == ' ')
1019 if (!strncmp(s, "Ctrl-", 5) || !strncmp(s, "CTRL-", 5))
1020 s += 5, mod |= CTRL;
1021 else if (!strncmp(s, "Shift-", 6) || !strncmp(s, "SHIFT-", 6))
1022 s += 6, mod |= SHIFT;
1023 else if (!strncmp(s, "Alt-", 4) || !strncmp(s, "ALT-", 4))
1030 if (strlen(s) == 1 && isascii(*s)) {
1035 key = toupper(key) - '@';
1037 ; // Alt not propagated to the gui
1039 for (char *t = s; *t; t++)
1041 for (int i = 0; keymap[i].name; i++) {
1042 if (!strcmp(s, keymap[i].name)) {
1043 key = keymap[i].key;
1054 ////////////////////////////////////////////////////////////////////////
1055 // Implementation of FGDialog::PropertyObject.
1056 ////////////////////////////////////////////////////////////////////////
1058 FGDialog::PropertyObject::PropertyObject(const char *n,
1059 puObject *o, SGPropertyNode_ptr p) :
1069 ////////////////////////////////////////////////////////////////////////
1070 // Implementation of fgValueList and derived pui widgets
1071 ////////////////////////////////////////////////////////////////////////
1074 fgValueList::fgValueList(SGPropertyNode *p) :
1081 fgValueList::update()
1087 fgValueList::~fgValueList()
1093 fgValueList::make_list()
1095 vector<SGPropertyNode_ptr> value_nodes = _props->getChildren("value");
1096 _list = new char *[value_nodes.size() + 1];
1098 for (i = 0; i < value_nodes.size(); i++)
1099 _list[i] = strdup((char *)value_nodes[i]->getStringValue());
1104 fgValueList::destroy_list()
1106 for (int i = 0; _list[i] != 0; i++)
1117 fgValueList::update();
1118 int top = getTopItem();
1123 // end of dialog.cxx