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
218 |PUCLASS_LARGEINPUT|PUCLASS_SCROLLBAR))
221 getPosition(&_dlgX, &_dlgY);
222 getSize(&_dlgW, &_dlgH);
223 _start_cursor = fgGetMouseCursor();
228 // check and prepare for resizing
229 static const int cursor[] = {
230 MOUSE_CURSOR_POINTER, MOUSE_CURSOR_LEFTSIDE, MOUSE_CURSOR_RIGHTSIDE, 0,
231 MOUSE_CURSOR_TOPSIDE, MOUSE_CURSOR_TOPLEFT, MOUSE_CURSOR_TOPRIGHT, 0,
232 MOUSE_CURSOR_BOTTOMSIDE, MOUSE_CURSOR_BOTTOMLEFT, MOUSE_CURSOR_BOTTOMRIGHT, 0,
236 if (!global_drag && _resizable) {
237 int hmargin = global_resize ? _dlgW / 3 : 10;
238 int vmargin = global_resize ? _dlgH / 3 : 10;
240 if (y - _dlgY < vmargin)
242 else if (_dlgY + _dlgH - y < vmargin)
245 if (x - _dlgX < hmargin)
247 else if (_dlgX + _dlgW - x < hmargin)
250 if (!_resizing && global_resize)
251 _resizing = BOTTOM|RIGHT;
253 _cursor = cursor[_resizing];
254 if (_resizing && _resizable)
255 fgSetMouseCursor(_cursor);
258 } else if (updown == PU_DRAG && _dragging) {
260 GUIInfo *info = (GUIInfo *)getUserData();
261 if (_resizable && info && info->node) {
264 if (_resizing & LEFT)
266 if (_resizing & RIGHT)
270 if (_resizing & BOTTOM)
274 LayoutWidget wid(info->node);
275 wid.calcPrefSize(&prefw, &prefh);
283 if (_resizing & LEFT)
285 if (_resizing & BOTTOM)
288 wid.layout(x, y, w, h);
291 applySize(static_cast<puObject *>(this));
292 getFirstChild()->setSize(w, h); // dialog background puFrame
295 setPosition(x + _dlgX - _startX, y + _dlgY - _startY);
298 } else if (_dragging) {
299 fgSetMouseCursor(_start_cursor);
305 int fgPopup::getHitObjects(puObject *object, int x, int y)
307 if (!object->isVisible())
311 if (object->getType() & PUCLASS_GROUP)
312 for (puObject *obj = ((puGroup *)object)->getFirstChild();
313 obj; obj = obj->getNextObject())
314 type |= getHitObjects(obj, x, y);
317 object->getAbsolutePosition(&cx, &cy);
318 object->getSize(&cw, &ch);
319 if (x >= cx && x < cx + cw && y >= cy && y < cy + ch)
320 type |= object->getType();
324 void fgPopup::applySize(puObject *object)
326 // compound plib widgets use setUserData() for internal purposes, so refuse
327 // to descend into anything that has other bits set than the following
328 const int validUserData = PUCLASS_VALUE|PUCLASS_OBJECT|PUCLASS_GROUP|PUCLASS_INTERFACE
329 |PUCLASS_FRAME|PUCLASS_TEXT|PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
330 |PUCLASS_ARROW|PUCLASS_DIAL|PUCLASS_POPUP;
332 int type = object->getType();
333 if (type & PUCLASS_GROUP && !(type & ~validUserData))
334 for (puObject *obj = ((puGroup *)object)->getFirstChild();
335 obj; obj = obj->getNextObject())
338 GUIInfo *info = (GUIInfo *)object->getUserData();
342 SGPropertyNode *n = info->node;
344 SG_LOG(SG_GENERAL, SG_ALERT, "fgPopup::applySize: no props");
347 int x = n->getIntValue("x");
348 int y = n->getIntValue("y");
349 int w = n->getIntValue("width", 4);
350 int h = n->getIntValue("height", 4);
351 object->setPosition(x, y);
352 object->setSize(w, h);
356 ////////////////////////////////////////////////////////////////////////
358 ////////////////////////////////////////////////////////////////////////
364 action_callback (puObject *object)
366 GUIInfo *info = (GUIInfo *)object->getUserData();
367 NewGUI *gui = (NewGUI *)globals->get_subsystem("gui");
368 gui->setActiveDialog(info->dialog);
369 int nBindings = info->bindings.size();
370 for (int i = 0; i < nBindings; i++) {
371 info->bindings[i]->fire();
372 if (gui->getActiveDialog() == 0)
375 gui->setActiveDialog(0);
380 ////////////////////////////////////////////////////////////////////////
381 // Static helper functions.
382 ////////////////////////////////////////////////////////////////////////
385 * Copy a property value to a PUI object.
388 copy_to_pui (SGPropertyNode *node, puObject *object)
390 GUIInfo *info = (GUIInfo *)object->getUserData();
392 SG_LOG(SG_GENERAL, SG_ALERT, "dialog: widget without GUIInfo!");
393 return; // this can't really happen
396 // Treat puText objects specially, so their "values" can be set
398 if (object->getType() & PUCLASS_TEXT) {
399 if (info->fmt_type != f_INVALID)
400 info->apply_format(node);
402 info->text = node->getStringValue();
404 object->setLabel(info->text.c_str());
408 switch (node->getType()) {
409 case SGPropertyNode::BOOL:
410 case SGPropertyNode::INT:
411 case SGPropertyNode::LONG:
412 object->setValue(node->getIntValue());
414 case SGPropertyNode::FLOAT:
415 case SGPropertyNode::DOUBLE:
416 object->setValue(node->getFloatValue());
419 info->text = node->getStringValue();
420 object->setValue(info->text.c_str());
427 copy_from_pui (puObject *object, SGPropertyNode *node)
429 // puText objects are immutable, so should not be copied out
430 if (object->getType() & PUCLASS_TEXT)
433 switch (node->getType()) {
434 case SGPropertyNode::BOOL:
435 case SGPropertyNode::INT:
436 case SGPropertyNode::LONG:
437 node->setIntValue(object->getIntegerValue());
439 case SGPropertyNode::FLOAT:
440 case SGPropertyNode::DOUBLE:
441 node->setFloatValue(object->getFloatValue());
444 const char *s = object->getStringValue();
446 node->setStringValue(s);
453 ////////////////////////////////////////////////////////////////////////
454 // Implementation of FGDialog.
455 ////////////////////////////////////////////////////////////////////////
457 FGDialog::FGDialog (SGPropertyNode *props) :
459 _gui((NewGUI *)globals->get_subsystem("gui")),
462 _module = string("__dlg:") + props->getStringValue("name", "[unnamed]");
463 SGPropertyNode *nasal = props->getNode("nasal");
465 _nasal_close = nasal->getNode("close");
466 SGPropertyNode *open = nasal->getNode("open");
468 const char *s = open->getStringValue();
469 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
470 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), props);
476 FGDialog::~FGDialog ()
479 _object->getAbsolutePosition(&x, &y);
480 _props->setIntValue("lastx", x);
481 _props->setIntValue("lasty", y);
483 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
485 const char *s = _nasal_close->getStringValue();
486 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
488 nas->deleteModule(_module.c_str());
490 puDeleteObject(_object);
493 // Delete all the info objects we
494 // were forced to keep around because
495 // PUI cannot delete its own user data.
496 for (i = 0; i < _info.size(); i++) {
497 delete (GUIInfo *)_info[i];
500 // Finally, delete the property links.
501 for (i = 0; i < _propertyObjects.size(); i++) {
502 delete _propertyObjects[i];
503 _propertyObjects[i] = 0;
508 FGDialog::updateValues (const char *objectName)
510 if (objectName && !objectName[0])
513 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
514 const string &name = _propertyObjects[i]->name;
515 if (objectName && name != objectName)
518 puObject *obj = _propertyObjects[i]->object;
519 if ((obj->getType() & PUCLASS_LIST) && (dynamic_cast<GUI_ID *>(obj)->id & FGCLASS_LIST)) {
520 fgList *pl = static_cast<fgList *>(obj);
523 copy_to_pui(_propertyObjects[i]->node, obj);
528 FGDialog::applyValues (const char *objectName)
530 if (objectName && !objectName[0])
533 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
534 const string &name = _propertyObjects[i]->name;
535 if (objectName && name != objectName)
538 copy_from_pui(_propertyObjects[i]->object,
539 _propertyObjects[i]->node);
546 for (unsigned int i = 0; i < _liveObjects.size(); i++) {
547 puObject *obj = _liveObjects[i]->object;
548 if (obj->getType() & PUCLASS_INPUT && ((puInput *)obj)->isAcceptingInput())
551 copy_to_pui(_liveObjects[i]->node, obj);
556 FGDialog::display (SGPropertyNode *props)
559 SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
563 int screenw = globals->get_props()->getIntValue("/sim/startup/xsize");
564 int screenh = globals->get_props()->getIntValue("/sim/startup/ysize");
566 bool userx = props->hasValue("x");
567 bool usery = props->hasValue("y");
568 bool userw = props->hasValue("width");
569 bool userh = props->hasValue("height");
571 // Let the layout widget work in the same property subtree.
572 LayoutWidget wid(props);
574 SGPropertyNode *fontnode = props->getNode("font");
576 FGFontCache *fc = globals->get_fontcache();
577 _font = fc->get(fontnode);
579 _font = _gui->getDefaultFont();
581 wid.setDefaultFont(_font, int(_font->getPointSize()));
584 int px, py, savex, savey;
585 if (!userw || !userh)
586 wid.calcPrefSize(&pw, &ph);
587 pw = props->getIntValue("width", pw);
588 ph = props->getIntValue("height", ph);
589 px = savex = props->getIntValue("x", (screenw - pw) / 2);
590 py = savey = props->getIntValue("y", (screenh - ph) / 2);
592 // Negative x/y coordinates are interpreted as distance from the top/right
593 // corner rather than bottom/left.
595 px = screenw - pw + px;
597 py = screenh - ph + py;
599 // Define "x", "y", "width" and/or "height" in the property tree if they
600 // are not specified in the configuration file.
601 wid.layout(px, py, pw, ph);
603 // Use the dimension and location properties as specified in the
604 // configuration file or from the layout widget.
605 _object = makeObject(props, screenw, screenh);
607 // Remove automatically generated properties, so the layout looks
608 // the same next time around, or restore x and y to preserve negative coords.
610 props->setIntValue("x", savex);
612 props->removeChild("x");
615 props->setIntValue("y", savey);
617 props->removeChild("y");
619 if (!userw) props->removeChild("width");
620 if (!userh) props->removeChild("height");
625 SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
626 << props->getStringValue("name", "[unnamed]")
627 << " does not contain a proper GUI definition");
632 FGDialog::makeObject (SGPropertyNode *props, int parentWidth, int parentHeight)
634 if (!props->getBoolValue("enabled", true))
637 bool presetSize = props->hasValue("width") && props->hasValue("height");
638 int width = props->getIntValue("width", parentWidth);
639 int height = props->getIntValue("height", parentHeight);
640 int x = props->getIntValue("x", (parentWidth - width) / 2);
641 int y = props->getIntValue("y", (parentHeight - height) / 2);
642 string type = props->getName();
647 if (type == "dialog") {
649 bool draggable = props->getBoolValue("draggable", true);
650 bool resizable = props->getBoolValue("resizable", false);
651 if (props->getBoolValue("modal", false))
652 obj = new puDialogBox(x, y);
654 obj = new fgPopup(x, y, resizable, draggable);
655 setupGroup(obj, props, width, height, true);
656 setColor(obj, props);
659 } else if (type == "group") {
660 puGroup *obj = new puGroup(x, y);
661 setupGroup(obj, props, width, height, false);
662 setColor(obj, props);
665 } else if (type == "frame") {
666 puGroup *obj = new puGroup(x, y);
667 setupGroup(obj, props, width, height, true);
668 setColor(obj, props);
671 } else if (type == "hrule" || type == "vrule") {
672 puFrame *obj = new puFrame(x, y, x + width, y + height);
673 obj->setBorderThickness(0);
674 setupObject(obj, props);
675 setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
678 } else if (type == "list") {
679 int slider_width = props->getIntValue("slider", 20);
680 fgList *obj = new fgList(x, y, x + width, y + height, props, slider_width);
682 obj->setSize(width, height);
683 setupObject(obj, props);
684 setColor(obj, props);
687 } else if (type == "airport-list") {
688 AirportList *obj = new AirportList(x, y, x + width, y + height);
690 obj->setSize(width, height);
691 setupObject(obj, props);
692 setColor(obj, props);
695 } else if (type == "property-list") {
696 PropertyList *obj = new PropertyList(x, y, x + width, y + height, globals->get_props());
698 obj->setSize(width, height);
699 setupObject(obj, props);
700 setColor(obj, props);
703 } else if (type == "input") {
704 puInput *obj = new puInput(x, y, x + width, y + height);
705 setupObject(obj, props);
706 setColor(obj, props, FOREGROUND|LABEL);
709 } else if (type == "text") {
710 puText *obj = new puText(x, y);
711 setupObject(obj, props);
713 // Layed-out objects need their size set, and non-layout ones
714 // get a different placement.
716 obj->setSize(width, height);
718 obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
719 setColor(obj, props, LABEL);
722 } else if (type == "checkbox") {
724 obj = new puButton(x, y, x + width, y + height, PUBUTTON_XCHECK);
725 setupObject(obj, props);
726 setColor(obj, props, FOREGROUND|LABEL);
729 } else if (type == "radio") {
731 obj = new puButton(x, y, x + width, y + height, PUBUTTON_CIRCLE);
732 setupObject(obj, props);
733 setColor(obj, props, FOREGROUND|LABEL);
736 } else if (type == "button") {
738 const char *legend = props->getStringValue("legend", "[none]");
739 if (props->getBoolValue("one-shot", true))
740 obj = new puOneShot(x, y, legend);
742 obj = new puButton(x, y, legend);
744 obj->setSize(width, height);
745 setupObject(obj, props);
746 setColor(obj, props);
749 } else if (type == "combo") {
750 fgComboBox *obj = new fgComboBox(x, y, x + width, y + height, props,
751 props->getBoolValue("editable", false));
752 setupObject(obj, props);
753 setColor(obj, props, EDITFIELD);
756 } else if (type == "slider") {
757 bool vertical = props->getBoolValue("vertical", false);
758 puSlider *obj = new puSlider(x, y, (vertical ? height : width), vertical);
759 obj->setMinValue(props->getFloatValue("min", 0.0));
760 obj->setMaxValue(props->getFloatValue("max", 1.0));
761 obj->setStepSize(props->getFloatValue("step"));
762 obj->setSliderFraction(props->getFloatValue("fraction"));
763 #if PLIB_VERSION > 185
764 obj->setPageStepSize(props->getFloatValue("pagestep"));
766 setupObject(obj, props);
768 obj->setSize(width, height);
769 setColor(obj, props, FOREGROUND|LABEL);
772 } else if (type == "dial") {
773 puDial *obj = new puDial(x, y, width);
774 obj->setMinValue(props->getFloatValue("min", 0.0));
775 obj->setMaxValue(props->getFloatValue("max", 1.0));
776 obj->setWrap(props->getBoolValue("wrap", true));
777 setupObject(obj, props);
778 setColor(obj, props, FOREGROUND|LABEL);
781 } else if (type == "textbox") {
782 int slider_width = props->getIntValue("slider", 20);
783 int wrap = props->getBoolValue("wrap", true);
784 #if PLIB_VERSION > 185
785 puaLargeInput *obj = new puaLargeInput(x, y,
786 x + width, x + height, 11, slider_width, wrap);
788 puaLargeInput *obj = new puaLargeInput(x, y,
789 x + width, x + height, 2, slider_width, wrap);
792 if (props->getBoolValue("editable"))
798 obj->setSize(width, height);
799 setupObject(obj, props);
800 setColor(obj, props, FOREGROUND|LABEL);
802 int top = props->getIntValue("top-line", 0);
803 obj->setTopLineInWindow(top < 0 ? unsigned(-1) >> 1 : top);
806 } else if (type == "select") {
807 fgSelectBox *obj = new fgSelectBox(x, y, x + width, y + height, props);
808 setupObject(obj, props);
809 setColor(obj, props, EDITFIELD);
817 FGDialog::setupObject (puObject *object, SGPropertyNode *props)
819 GUIInfo *info = new GUIInfo(this);
820 object->setUserData(info);
821 _info.push_back(info);
822 object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
823 object->makeReturnDefault(props->getBoolValue("default"));
826 if (props->hasValue("legend")) {
827 info->legend = props->getStringValue("legend");
828 object->setLegend(info->legend.c_str());
831 if (props->hasValue("label")) {
832 info->label = props->getStringValue("label");
833 object->setLabel(info->label.c_str());
836 if (props->hasValue("border"))
837 object->setBorderThickness( props->getIntValue("border", 2) );
839 if (SGPropertyNode *nft = props->getNode("font", false)) {
840 FGFontCache *fc = globals->get_fontcache();
841 puFont *lfnt = fc->get(nft);
842 object->setLabelFont(*lfnt);
843 object->setLegendFont(*lfnt);
845 object->setLabelFont(*_font);
848 if (props->hasValue("property")) {
849 const char *name = props->getStringValue("name");
852 const char *propname = props->getStringValue("property");
853 SGPropertyNode_ptr node = fgGetNode(propname, true);
854 copy_to_pui(node, object);
856 PropertyObject *po = new PropertyObject(name, object, node);
857 _propertyObjects.push_back(po);
858 if (props->getBoolValue("live"))
859 _liveObjects.push_back(po);
862 SGPropertyNode *dest = fgGetNode("/sim/bindings/gui", true);
863 vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
864 if (bindings.size() > 0) {
865 info->key = props->getIntValue("keynum", -1);
866 if (props->hasValue("key"))
867 info->key = getKeyCode(props->getStringValue("key", ""));
869 for (unsigned int i = 0; i < bindings.size(); i++) {
871 SGPropertyNode_ptr binding;
872 while (dest->getChild("binding", j))
875 const char *cmd = bindings[i]->getStringValue("command");
876 if (!strcmp(cmd, "nasal"))
877 bindings[i]->setStringValue("module", _module.c_str());
879 binding = dest->getChild("binding", j, true);
880 copyProperties(bindings[i], binding);
881 info->bindings.push_back(new SGBinding(binding, globals->get_props()));
883 object->setCallback(action_callback);
886 string type = props->getName();
887 if (type == "input" && props->getBoolValue("live"))
888 object->setDownCallback(action_callback);
890 if (type == "text") {
891 const char *format = props->getStringValue("format", 0);
893 info->fmt_type = validate_format(format);
894 if (info->fmt_type != f_INVALID)
895 info->format = format;
897 SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
904 FGDialog::setupGroup(puGroup *group, SGPropertyNode *props,
905 int width, int height, bool makeFrame)
907 setupObject(group, props);
910 puFrame* f = new puFrame(0, 0, width, height);
914 int nChildren = props->nChildren();
915 for (int i = 0; i < nChildren; i++)
916 makeObject(props->getChild(i), width, height);
921 FGDialog::setColor(puObject *object, SGPropertyNode *props, int which)
923 string type = props->getName();
926 if (type == "textbox" && props->getBoolValue("editable"))
929 FGColor c(_gui->getColor("background"));
930 c.merge(_gui->getColor(type));
931 c.merge(props->getNode("color"));
933 object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha());
941 { BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" },
942 { FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" },
943 { HIGHLIGHT, PUCOL_HIGHLIGHT, "highlight", "color-highlight" },
944 { LABEL, PUCOL_LABEL, "label", "color-label" },
945 { LEGEND, PUCOL_LEGEND, "legend", "color-legend" },
946 { MISC, PUCOL_MISC, "misc", "color-misc" },
947 { EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
950 const int numcol = sizeof(pucol) / sizeof(pucol[0]);
952 for (int i = 0; i < numcol; i++) {
957 dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name));
958 if (which & pucol[i].mask)
959 dirty |= c.merge(props->getNode("color"));
961 if ((pucol[i].mask == LABEL) && !c.isValid())
962 dirty |= c.merge(_gui->getColor("label"));
964 dirty |= c.merge(props->getNode(pucol[i].cname));
966 if (c.isValid() && dirty)
967 object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha());
999 {"left", PU_KEY_LEFT},
1001 {"right", PU_KEY_RIGHT},
1002 {"down", PU_KEY_DOWN},
1003 {"pageup", PU_KEY_PAGE_UP},
1004 {"pagedn", PU_KEY_PAGE_DOWN},
1005 {"home", PU_KEY_HOME},
1006 {"end", PU_KEY_END},
1007 {"insert", PU_KEY_INSERT},
1012 FGDialog::getKeyCode(const char *str)
1023 char *buf = new char[strlen(str) + 1];
1025 char *s = buf + strlen(buf);
1026 while (s > str && s[-1] == ' ')
1033 if (!strncmp(s, "Ctrl-", 5) || !strncmp(s, "CTRL-", 5))
1034 s += 5, mod |= CTRL;
1035 else if (!strncmp(s, "Shift-", 6) || !strncmp(s, "SHIFT-", 6))
1036 s += 6, mod |= SHIFT;
1037 else if (!strncmp(s, "Alt-", 4) || !strncmp(s, "ALT-", 4))
1044 if (strlen(s) == 1 && isascii(*s)) {
1049 key = toupper(key) - '@';
1051 ; // Alt not propagated to the gui
1053 for (char *t = s; *t; t++)
1055 for (int i = 0; keymap[i].name; i++) {
1056 if (!strcmp(s, keymap[i].name)) {
1057 key = keymap[i].key;
1068 ////////////////////////////////////////////////////////////////////////
1069 // Implementation of FGDialog::PropertyObject.
1070 ////////////////////////////////////////////////////////////////////////
1072 FGDialog::PropertyObject::PropertyObject(const char *n,
1073 puObject *o, SGPropertyNode_ptr p) :
1083 ////////////////////////////////////////////////////////////////////////
1084 // Implementation of fgValueList and derived pui widgets
1085 ////////////////////////////////////////////////////////////////////////
1088 fgValueList::fgValueList(SGPropertyNode *p) :
1095 fgValueList::update()
1101 fgValueList::~fgValueList()
1107 fgValueList::make_list()
1109 vector<SGPropertyNode_ptr> value_nodes = _props->getChildren("value");
1110 _list = new char *[value_nodes.size() + 1];
1112 for (i = 0; i < value_nodes.size(); i++)
1113 _list[i] = strdup((char *)value_nodes[i]->getStringValue());
1118 fgValueList::destroy_list()
1120 for (int i = 0; _list[i] != 0; i++)
1131 fgValueList::update();
1132 int top = getTopItem();
1137 // end of dialog.cxx