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;
20 static const int RESIZE_MARGIN = 7;
24 * Makes sure the format matches '%[ -+#]?\d*(\.\d*)?(l?[df]|s)', with
25 * only one number or string placeholder and otherwise arbitrary prefix
26 * and postfix containing only quoted percent signs (%%).
29 validate_format(const char *f)
43 while (*f == ' ' || *f == '+' || *f == '-' || *f == '#' || *f == '0')
45 while (*f && isdigit(*f))
49 while (*f && isdigit(*f))
57 type = l ? f_LONG : f_INT;
59 type = l ? f_DOUBLE : f_FLOAT;
79 ////////////////////////////////////////////////////////////////////////
80 // Implementation of GUIInfo.
81 ////////////////////////////////////////////////////////////////////////
84 * User data for a GUI object.
90 void apply_format(SGPropertyNode *);
93 SGPropertyNode_ptr node;
94 vector <SGBinding *> bindings;
96 string label, legend, text, format;
100 GUIInfo::GUIInfo (FGDialog *d) :
109 for (unsigned int i = 0; i < bindings.size(); i++) {
115 void GUIInfo::apply_format(SGPropertyNode *n)
117 char buf[FORMAT_BUFSIZE + 1];
118 if (fmt_type == f_INT)
119 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getIntValue());
120 else if (fmt_type == f_LONG)
121 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getLongValue());
122 else if (fmt_type == f_FLOAT)
123 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getFloatValue());
124 else if (fmt_type == f_DOUBLE)
125 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getDoubleValue());
127 snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getStringValue());
129 buf[FORMAT_BUFSIZE] = '\0';
138 int fgPopup::checkKey(int key, int updown)
140 if (updown == PU_UP || !isVisible() || !isActive() || window != puGetWindow())
143 puObject *input = getActiveInputField(this);
145 return input->checkKey(key, updown);
147 puObject *object = getKeyObject(this, key);
149 return puPopup::checkKey(key, updown);
151 // invokeCallback() isn't enough; we need to simulate a mouse button press
152 object->checkHit(PU_LEFT_BUTTON, PU_DOWN,
153 (object->getABox()->min[0] + object->getABox()->max[0]) / 2,
154 (object->getABox()->min[1] + object->getABox()->max[1]) / 2);
155 object->checkHit(PU_LEFT_BUTTON, PU_UP,
156 (object->getABox()->min[0] + object->getABox()->max[0]) / 2,
157 (object->getABox()->min[1] + object->getABox()->max[1]) / 2);
161 puObject *fgPopup::getKeyObject(puObject *object, int key)
164 if (object->getType() & PUCLASS_GROUP)
165 for (puObject *obj = ((puGroup *)object)->getFirstChild();
166 obj; obj = obj->getNextObject())
167 if ((ret = getKeyObject(obj, key)))
170 GUIInfo *info = (GUIInfo *)object->getUserData();
171 if (info && info->key == key)
177 puObject *fgPopup::getActiveInputField(puObject *object)
180 if (object->getType() & PUCLASS_GROUP)
181 for (puObject *obj = ((puGroup *)object)->getFirstChild();
182 obj; obj = obj->getNextObject())
183 if ((ret = getActiveInputField(obj)))
186 if (object->getType() & (PUCLASS_INPUT|PUCLASS_LARGEINPUT)
187 && ((puInput *)object)->isAcceptingInput())
196 int fgPopup::checkHit(int button, int updown, int x, int y)
199 if (updown != PU_DRAG && !_dragging)
200 result = puPopup::checkHit(button, updown, x, y);
205 // This is annoying. We would really want a true result from the
206 // superclass to indicate "handled by child object", but all it
207 // tells us is that the pointer is inside the dialog. So do the
208 // intersection test (again) to make sure we don't start a drag
209 // when inside controls.
211 if (updown == PU_DOWN && !_dragging) {
214 int global_drag = fgGetKeyModifiers() & KEYMOD_SHIFT;
215 int global_resize = fgGetKeyModifiers() & KEYMOD_CTRL;
217 int hit = getHitObjects(this, x, y);
218 if (hit & PUCLASS_LIST) // ctrl-click in property browser (toggle bool)
220 if (!global_resize && hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
221 |PUCLASS_LARGEINPUT|PUCLASS_SCROLLBAR))
224 getPosition(&_dlgX, &_dlgY);
225 getSize(&_dlgW, &_dlgH);
226 _start_cursor = fgGetMouseCursor();
231 // check and prepare for resizing
232 static const int cursor[] = {
233 MOUSE_CURSOR_POINTER, MOUSE_CURSOR_LEFTSIDE, MOUSE_CURSOR_RIGHTSIDE, 0,
234 MOUSE_CURSOR_TOPSIDE, MOUSE_CURSOR_TOPLEFT, MOUSE_CURSOR_TOPRIGHT, 0,
235 MOUSE_CURSOR_BOTTOMSIDE, MOUSE_CURSOR_BOTTOMLEFT, MOUSE_CURSOR_BOTTOMRIGHT, 0,
239 if (!global_drag && _resizable) {
240 int hmargin = global_resize ? _dlgW / 3 : RESIZE_MARGIN;
241 int vmargin = global_resize ? _dlgH / 3 : RESIZE_MARGIN;
243 if (y - _dlgY < vmargin)
245 else if (_dlgY + _dlgH - y < vmargin)
248 if (x - _dlgX < hmargin)
250 else if (_dlgX + _dlgW - x < hmargin)
253 if (!_resizing && global_resize)
254 _resizing = BOTTOM|RIGHT;
256 _cursor = cursor[_resizing];
257 if (_resizing && _resizable)
258 fgSetMouseCursor(_cursor);
261 } else if (updown == PU_DRAG && _dragging) {
263 GUIInfo *info = (GUIInfo *)getUserData();
264 if (_resizable && info && info->node) {
267 if (_resizing & LEFT)
269 if (_resizing & RIGHT)
273 if (_resizing & BOTTOM)
277 LayoutWidget wid(info->node);
278 wid.calcPrefSize(&prefw, &prefh);
286 if (_resizing & LEFT)
288 if (_resizing & BOTTOM)
291 wid.layout(x, y, w, h);
294 applySize(static_cast<puObject *>(this));
295 getFirstChild()->setSize(w, h); // dialog background puFrame
298 setPosition(x + _dlgX - _startX, y + _dlgY - _startY);
301 } else if (_dragging) {
302 fgSetMouseCursor(_start_cursor);
308 int fgPopup::getHitObjects(puObject *object, int x, int y)
310 if (!object->isVisible())
314 if (object->getType() & PUCLASS_GROUP)
315 for (puObject *obj = ((puGroup *)object)->getFirstChild();
316 obj; obj = obj->getNextObject())
317 type |= getHitObjects(obj, x, y);
320 object->getAbsolutePosition(&cx, &cy);
321 object->getSize(&cw, &ch);
322 if (x >= cx && x < cx + cw && y >= cy && y < cy + ch)
323 type |= object->getType();
327 void fgPopup::applySize(puObject *object)
329 // compound plib widgets use setUserData() for internal purposes, so refuse
330 // to descend into anything that has other bits set than the following
331 const int validUserData = PUCLASS_VALUE|PUCLASS_OBJECT|PUCLASS_GROUP|PUCLASS_INTERFACE
332 |PUCLASS_FRAME|PUCLASS_TEXT|PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
333 |PUCLASS_ARROW|PUCLASS_DIAL|PUCLASS_POPUP;
335 int type = object->getType();
336 if (type & PUCLASS_GROUP && !(type & ~validUserData))
337 for (puObject *obj = ((puGroup *)object)->getFirstChild();
338 obj; obj = obj->getNextObject())
341 GUIInfo *info = (GUIInfo *)object->getUserData();
345 SGPropertyNode *n = info->node;
347 SG_LOG(SG_GENERAL, SG_ALERT, "fgPopup::applySize: no props");
350 int x = n->getIntValue("x");
351 int y = n->getIntValue("y");
352 int w = n->getIntValue("width", 4);
353 int h = n->getIntValue("height", 4);
354 object->setPosition(x, y);
355 object->setSize(w, h);
359 ////////////////////////////////////////////////////////////////////////
361 ////////////////////////////////////////////////////////////////////////
367 action_callback (puObject *object)
369 GUIInfo *info = (GUIInfo *)object->getUserData();
370 NewGUI *gui = (NewGUI *)globals->get_subsystem("gui");
371 gui->setActiveDialog(info->dialog);
372 int nBindings = info->bindings.size();
373 for (int i = 0; i < nBindings; i++) {
374 info->bindings[i]->fire();
375 if (gui->getActiveDialog() == 0)
378 gui->setActiveDialog(0);
383 ////////////////////////////////////////////////////////////////////////
384 // Static helper functions.
385 ////////////////////////////////////////////////////////////////////////
388 * Copy a property value to a PUI object.
391 copy_to_pui (SGPropertyNode *node, puObject *object)
393 GUIInfo *info = (GUIInfo *)object->getUserData();
395 SG_LOG(SG_GENERAL, SG_ALERT, "dialog: widget without GUIInfo!");
396 return; // this can't really happen
399 // Treat puText objects specially, so their "values" can be set
401 if (object->getType() & PUCLASS_TEXT) {
402 if (info->fmt_type != f_INVALID)
403 info->apply_format(node);
405 info->text = node->getStringValue();
407 object->setLabel(info->text.c_str());
411 switch (node->getType()) {
412 case SGPropertyNode::BOOL:
413 case SGPropertyNode::INT:
414 case SGPropertyNode::LONG:
415 object->setValue(node->getIntValue());
417 case SGPropertyNode::FLOAT:
418 case SGPropertyNode::DOUBLE:
419 object->setValue(node->getFloatValue());
422 info->text = node->getStringValue();
423 object->setValue(info->text.c_str());
430 copy_from_pui (puObject *object, SGPropertyNode *node)
432 // puText objects are immutable, so should not be copied out
433 if (object->getType() & PUCLASS_TEXT)
436 switch (node->getType()) {
437 case SGPropertyNode::BOOL:
438 case SGPropertyNode::INT:
439 case SGPropertyNode::LONG:
440 node->setIntValue(object->getIntegerValue());
442 case SGPropertyNode::FLOAT:
443 case SGPropertyNode::DOUBLE:
444 node->setFloatValue(object->getFloatValue());
447 const char *s = object->getStringValue();
449 node->setStringValue(s);
456 ////////////////////////////////////////////////////////////////////////
457 // Implementation of FGDialog.
458 ////////////////////////////////////////////////////////////////////////
460 FGDialog::FGDialog (SGPropertyNode *props) :
462 _gui((NewGUI *)globals->get_subsystem("gui")),
465 _module = string("__dlg:") + props->getStringValue("name", "[unnamed]");
466 SGPropertyNode *nasal = props->getNode("nasal");
468 _nasal_close = nasal->getNode("close");
469 SGPropertyNode *open = nasal->getNode("open");
471 const char *s = open->getStringValue();
472 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
473 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), props);
479 FGDialog::~FGDialog ()
482 _object->getAbsolutePosition(&x, &y);
483 _props->setIntValue("lastx", x);
484 _props->setIntValue("lasty", y);
486 FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
488 const char *s = _nasal_close->getStringValue();
489 nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
491 nas->deleteModule(_module.c_str());
493 puDeleteObject(_object);
496 // Delete all the info objects we
497 // were forced to keep around because
498 // PUI cannot delete its own user data.
499 for (i = 0; i < _info.size(); i++) {
500 delete (GUIInfo *)_info[i];
503 // Finally, delete the property links.
504 for (i = 0; i < _propertyObjects.size(); i++) {
505 delete _propertyObjects[i];
506 _propertyObjects[i] = 0;
511 FGDialog::updateValues (const char *objectName)
513 if (objectName && !objectName[0])
516 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
517 const string &name = _propertyObjects[i]->name;
518 if (objectName && name != objectName)
521 puObject *obj = _propertyObjects[i]->object;
522 if ((obj->getType() & PUCLASS_LIST) && (dynamic_cast<GUI_ID *>(obj)->id & FGCLASS_LIST)) {
523 fgList *pl = static_cast<fgList *>(obj);
526 copy_to_pui(_propertyObjects[i]->node, obj);
531 FGDialog::applyValues (const char *objectName)
533 if (objectName && !objectName[0])
536 for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
537 const string &name = _propertyObjects[i]->name;
538 if (objectName && name != objectName)
541 copy_from_pui(_propertyObjects[i]->object,
542 _propertyObjects[i]->node);
549 for (unsigned int i = 0; i < _liveObjects.size(); i++) {
550 puObject *obj = _liveObjects[i]->object;
551 if (obj->getType() & PUCLASS_INPUT && ((puInput *)obj)->isAcceptingInput())
554 copy_to_pui(_liveObjects[i]->node, obj);
559 FGDialog::display (SGPropertyNode *props)
562 SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
566 int screenw = globals->get_props()->getIntValue("/sim/startup/xsize");
567 int screenh = globals->get_props()->getIntValue("/sim/startup/ysize");
569 bool userx = props->hasValue("x");
570 bool usery = props->hasValue("y");
571 bool userw = props->hasValue("width");
572 bool userh = props->hasValue("height");
574 // Let the layout widget work in the same property subtree.
575 LayoutWidget wid(props);
577 SGPropertyNode *fontnode = props->getNode("font");
579 FGFontCache *fc = globals->get_fontcache();
580 _font = fc->get(fontnode);
582 _font = _gui->getDefaultFont();
584 wid.setDefaultFont(_font, int(_font->getPointSize()));
587 int px, py, savex, savey;
588 if (!userw || !userh)
589 wid.calcPrefSize(&pw, &ph);
590 pw = props->getIntValue("width", pw);
591 ph = props->getIntValue("height", ph);
592 px = savex = props->getIntValue("x", (screenw - pw) / 2);
593 py = savey = props->getIntValue("y", (screenh - ph) / 2);
595 // Negative x/y coordinates are interpreted as distance from the top/right
596 // corner rather than bottom/left.
598 px = screenw - pw + px;
600 py = screenh - ph + py;
602 // Define "x", "y", "width" and/or "height" in the property tree if they
603 // are not specified in the configuration file.
604 wid.layout(px, py, pw, ph);
606 // Use the dimension and location properties as specified in the
607 // configuration file or from the layout widget.
608 _object = makeObject(props, screenw, screenh);
610 // Remove automatically generated properties, so the layout looks
611 // the same next time around, or restore x and y to preserve negative coords.
613 props->setIntValue("x", savex);
615 props->removeChild("x");
618 props->setIntValue("y", savey);
620 props->removeChild("y");
622 if (!userw) props->removeChild("width");
623 if (!userh) props->removeChild("height");
628 SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
629 << props->getStringValue("name", "[unnamed]")
630 << " does not contain a proper GUI definition");
635 FGDialog::makeObject (SGPropertyNode *props, int parentWidth, int parentHeight)
637 if (!props->getBoolValue("enabled", true))
640 bool presetSize = props->hasValue("width") && props->hasValue("height");
641 int width = props->getIntValue("width", parentWidth);
642 int height = props->getIntValue("height", parentHeight);
643 int x = props->getIntValue("x", (parentWidth - width) / 2);
644 int y = props->getIntValue("y", (parentHeight - height) / 2);
645 string type = props->getName();
650 if (type == "dialog") {
652 bool draggable = props->getBoolValue("draggable", true);
653 bool resizable = props->getBoolValue("resizable", false);
654 if (props->getBoolValue("modal", false))
655 obj = new puDialogBox(x, y);
657 obj = new fgPopup(x, y, resizable, draggable);
658 setupGroup(obj, props, width, height, true);
659 setColor(obj, props);
662 } else if (type == "group") {
663 puGroup *obj = new puGroup(x, y);
664 setupGroup(obj, props, width, height, false);
665 setColor(obj, props);
668 } else if (type == "frame") {
669 puGroup *obj = new puGroup(x, y);
670 setupGroup(obj, props, width, height, true);
671 setColor(obj, props);
674 } else if (type == "hrule" || type == "vrule") {
675 puFrame *obj = new puFrame(x, y, x + width, y + height);
676 obj->setBorderThickness(0);
677 setupObject(obj, props);
678 setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
681 } else if (type == "list") {
682 int slider_width = props->getIntValue("slider", 20);
683 fgList *obj = new fgList(x, y, x + width, y + height, props, slider_width);
685 obj->setSize(width, height);
686 setupObject(obj, props);
687 setColor(obj, props);
690 } else if (type == "airport-list") {
691 AirportList *obj = new AirportList(x, y, x + width, y + height);
693 obj->setSize(width, height);
694 setupObject(obj, props);
695 setColor(obj, props);
698 } else if (type == "property-list") {
699 PropertyList *obj = new PropertyList(x, y, x + width, y + height, globals->get_props());
701 obj->setSize(width, height);
702 setupObject(obj, props);
703 setColor(obj, props);
706 } else if (type == "input") {
707 puInput *obj = new puInput(x, y, x + width, y + height);
708 setupObject(obj, props);
709 setColor(obj, props, FOREGROUND|LABEL);
712 } else if (type == "text") {
713 puText *obj = new puText(x, y);
714 setupObject(obj, props);
716 // Layed-out objects need their size set, and non-layout ones
717 // get a different placement.
719 obj->setSize(width, height);
721 obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
722 setColor(obj, props, LABEL);
725 } else if (type == "checkbox") {
727 obj = new puButton(x, y, x + width, y + height, PUBUTTON_XCHECK);
728 setupObject(obj, props);
729 setColor(obj, props, FOREGROUND|LABEL);
732 } else if (type == "radio") {
734 obj = new puButton(x, y, x + width, y + height, PUBUTTON_CIRCLE);
735 setupObject(obj, props);
736 setColor(obj, props, FOREGROUND|LABEL);
739 } else if (type == "button") {
741 const char *legend = props->getStringValue("legend", "[none]");
742 if (props->getBoolValue("one-shot", true))
743 obj = new puOneShot(x, y, legend);
745 obj = new puButton(x, y, legend);
747 obj->setSize(width, height);
748 setupObject(obj, props);
749 setColor(obj, props);
752 } else if (type == "combo") {
753 fgComboBox *obj = new fgComboBox(x, y, x + width, y + height, props,
754 props->getBoolValue("editable", false));
755 setupObject(obj, props);
756 setColor(obj, props, EDITFIELD);
759 } else if (type == "slider") {
760 bool vertical = props->getBoolValue("vertical", false);
761 puSlider *obj = new puSlider(x, y, (vertical ? height : width), vertical);
762 obj->setMinValue(props->getFloatValue("min", 0.0));
763 obj->setMaxValue(props->getFloatValue("max", 1.0));
764 obj->setStepSize(props->getFloatValue("step"));
765 obj->setSliderFraction(props->getFloatValue("fraction"));
766 #if PLIB_VERSION > 185
767 obj->setPageStepSize(props->getFloatValue("pagestep"));
769 setupObject(obj, props);
771 obj->setSize(width, height);
772 setColor(obj, props, FOREGROUND|LABEL);
775 } else if (type == "dial") {
776 puDial *obj = new puDial(x, y, width);
777 obj->setMinValue(props->getFloatValue("min", 0.0));
778 obj->setMaxValue(props->getFloatValue("max", 1.0));
779 obj->setWrap(props->getBoolValue("wrap", true));
780 setupObject(obj, props);
781 setColor(obj, props, FOREGROUND|LABEL);
784 } else if (type == "textbox") {
785 int slider_width = props->getIntValue("slider", 20);
786 int wrap = props->getBoolValue("wrap", true);
787 #if PLIB_VERSION > 185
788 puaLargeInput *obj = new puaLargeInput(x, y,
789 x + width, x + height, 11, slider_width, wrap);
791 puaLargeInput *obj = new puaLargeInput(x, y,
792 x + width, x + height, 2, slider_width, wrap);
795 if (props->getBoolValue("editable"))
801 obj->setSize(width, height);
802 setupObject(obj, props);
803 setColor(obj, props, FOREGROUND|LABEL);
805 int top = props->getIntValue("top-line", 0);
806 obj->setTopLineInWindow(top < 0 ? unsigned(-1) >> 1 : top);
809 } else if (type == "select") {
810 fgSelectBox *obj = new fgSelectBox(x, y, x + width, y + height, props);
811 setupObject(obj, props);
812 setColor(obj, props, EDITFIELD);
820 FGDialog::setupObject (puObject *object, SGPropertyNode *props)
822 GUIInfo *info = new GUIInfo(this);
823 object->setUserData(info);
824 _info.push_back(info);
825 object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
826 object->makeReturnDefault(props->getBoolValue("default"));
829 if (props->hasValue("legend")) {
830 info->legend = props->getStringValue("legend");
831 object->setLegend(info->legend.c_str());
834 if (props->hasValue("label")) {
835 info->label = props->getStringValue("label");
836 object->setLabel(info->label.c_str());
839 if (props->hasValue("border"))
840 object->setBorderThickness( props->getIntValue("border", 2) );
842 if (SGPropertyNode *nft = props->getNode("font", false)) {
843 FGFontCache *fc = globals->get_fontcache();
844 puFont *lfnt = fc->get(nft);
845 object->setLabelFont(*lfnt);
846 object->setLegendFont(*lfnt);
848 object->setLabelFont(*_font);
851 string type = props->getName();
852 if (type == "input" && props->getBoolValue("live"))
853 object->setDownCallback(action_callback);
855 if (type == "text") {
856 const char *format = props->getStringValue("format", 0);
858 info->fmt_type = validate_format(format);
859 if (info->fmt_type != f_INVALID)
860 info->format = format;
862 SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
867 if (props->hasValue("property")) {
868 const char *name = props->getStringValue("name");
871 const char *propname = props->getStringValue("property");
872 SGPropertyNode_ptr node = fgGetNode(propname, true);
873 copy_to_pui(node, object);
875 PropertyObject *po = new PropertyObject(name, object, node);
876 _propertyObjects.push_back(po);
877 if (props->getBoolValue("live"))
878 _liveObjects.push_back(po);
881 SGPropertyNode *dest = fgGetNode("/sim/bindings/gui", true);
882 vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
883 if (bindings.size() > 0) {
884 info->key = props->getIntValue("keynum", -1);
885 if (props->hasValue("key"))
886 info->key = getKeyCode(props->getStringValue("key", ""));
888 for (unsigned int i = 0; i < bindings.size(); i++) {
890 SGPropertyNode_ptr binding;
891 while (dest->getChild("binding", j))
894 const char *cmd = bindings[i]->getStringValue("command");
895 if (!strcmp(cmd, "nasal"))
896 bindings[i]->setStringValue("module", _module.c_str());
898 binding = dest->getChild("binding", j, true);
899 copyProperties(bindings[i], binding);
900 info->bindings.push_back(new SGBinding(binding, globals->get_props()));
902 object->setCallback(action_callback);
907 FGDialog::setupGroup(puGroup *group, SGPropertyNode *props,
908 int width, int height, bool makeFrame)
910 setupObject(group, props);
913 puFrame* f = new puFrame(0, 0, width, height);
917 int nChildren = props->nChildren();
918 for (int i = 0; i < nChildren; i++)
919 makeObject(props->getChild(i), width, height);
924 FGDialog::setColor(puObject *object, SGPropertyNode *props, int which)
926 string type = props->getName();
929 if (type == "textbox" && props->getBoolValue("editable"))
932 FGColor c(_gui->getColor("background"));
933 c.merge(_gui->getColor(type));
934 c.merge(props->getNode("color"));
936 object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha());
944 { BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" },
945 { FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" },
946 { HIGHLIGHT, PUCOL_HIGHLIGHT, "highlight", "color-highlight" },
947 { LABEL, PUCOL_LABEL, "label", "color-label" },
948 { LEGEND, PUCOL_LEGEND, "legend", "color-legend" },
949 { MISC, PUCOL_MISC, "misc", "color-misc" },
950 { EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
953 const int numcol = sizeof(pucol) / sizeof(pucol[0]);
955 for (int i = 0; i < numcol; i++) {
960 dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name));
961 if (which & pucol[i].mask)
962 dirty |= c.merge(props->getNode("color"));
964 if ((pucol[i].mask == LABEL) && !c.isValid())
965 dirty |= c.merge(_gui->getColor("label"));
967 dirty |= c.merge(props->getNode(pucol[i].cname));
969 if (c.isValid() && dirty)
970 object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha());
1000 {"f11", PU_KEY_F11},
1001 {"f12", PU_KEY_F12},
1002 {"left", PU_KEY_LEFT},
1004 {"right", PU_KEY_RIGHT},
1005 {"down", PU_KEY_DOWN},
1006 {"pageup", PU_KEY_PAGE_UP},
1007 {"pagedn", PU_KEY_PAGE_DOWN},
1008 {"home", PU_KEY_HOME},
1009 {"end", PU_KEY_END},
1010 {"insert", PU_KEY_INSERT},
1015 FGDialog::getKeyCode(const char *str)
1026 char *buf = new char[strlen(str) + 1];
1028 char *s = buf + strlen(buf);
1029 while (s > str && s[-1] == ' ')
1036 if (!strncmp(s, "Ctrl-", 5) || !strncmp(s, "CTRL-", 5))
1037 s += 5, mod |= CTRL;
1038 else if (!strncmp(s, "Shift-", 6) || !strncmp(s, "SHIFT-", 6))
1039 s += 6, mod |= SHIFT;
1040 else if (!strncmp(s, "Alt-", 4) || !strncmp(s, "ALT-", 4))
1047 if (strlen(s) == 1 && isascii(*s)) {
1052 key = toupper(key) - '@';
1054 ; // Alt not propagated to the gui
1056 for (char *t = s; *t; t++)
1058 for (int i = 0; keymap[i].name; i++) {
1059 if (!strcmp(s, keymap[i].name)) {
1060 key = keymap[i].key;
1071 ////////////////////////////////////////////////////////////////////////
1072 // Implementation of FGDialog::PropertyObject.
1073 ////////////////////////////////////////////////////////////////////////
1075 FGDialog::PropertyObject::PropertyObject(const char *n,
1076 puObject *o, SGPropertyNode_ptr p) :
1086 ////////////////////////////////////////////////////////////////////////
1087 // Implementation of fgValueList and derived pui widgets
1088 ////////////////////////////////////////////////////////////////////////
1091 fgValueList::fgValueList(SGPropertyNode *p) :
1098 fgValueList::update()
1104 fgValueList::~fgValueList()
1110 fgValueList::make_list()
1112 vector<SGPropertyNode_ptr> value_nodes = _props->getChildren("value");
1113 _list = new char *[value_nodes.size() + 1];
1115 for (i = 0; i < value_nodes.size(); i++)
1116 _list[i] = strdup((char *)value_nodes[i]->getStringValue());
1121 fgValueList::destroy_list()
1123 for (int i = 0; _list[i] != 0; i++)
1134 fgValueList::update();
1135 int top = getTopItem();
1140 // end of dialog.cxx