]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/dialog.cxx
replace depreciated plib symbols with their new forms
[flightgear.git] / src / GUI / dialog.cxx
index 3b2484150391344f7ca852462b2ee0a05dd6580e..f9f324e58b4c1e545bc8d47ff4532470ef52dac1 100644 (file)
 #include "AirportList.hxx"
 #include "layout.hxx"
 
+////////////////////////////////////////////////////////////////////////
+// Implementation of GUIInfo.
+////////////////////////////////////////////////////////////////////////
+
+/**
+ * User data for a GUI object.
+ */
+struct GUIInfo
+{
+    GUIInfo (FGDialog * d);
+    virtual ~GUIInfo ();
+
+    FGDialog * dialog;
+    vector <FGBinding *> bindings;
+    int key;
+};
+
+GUIInfo::GUIInfo (FGDialog * d)
+    : dialog(d),
+      key(-1)
+{
+}
+
+GUIInfo::~GUIInfo ()
+{
+    for (unsigned int i = 0; i < bindings.size(); i++) {
+        delete bindings[i];
+        bindings[i] = 0;
+    }
+}
+
+\f
+/**
+ * Key handler.
+ */
+int fgPopup::checkKey(int key, int updown)
+{
+    if (updown == PU_UP || !isVisible() || !isActive() || window != puGetWindow())
+        return false;
+
+    puObject *input = getActiveInputField(this);
+    if (input)
+        return input->checkKey(key, updown);
+
+    puObject *object = getKeyObject(this, key);
+    if (!object)
+        return puPopup::checkKey(key, updown);
+
+    object->invokeCallback() ;
+    return true;
+}
+
+puObject *fgPopup::getKeyObject(puObject *object, int key)
+{
+    puObject *ret;
+    if(object->getType() & PUCLASS_GROUP)
+        for (puObject *obj = ((puGroup *)object)->getFirstChild();
+                obj; obj = obj->getNextObject())
+            if ((ret = getKeyObject(obj, key)))
+                return ret;
+
+    GUIInfo *info = (GUIInfo *)object->getUserData();
+    if (info && info->key == key)
+       return object;
+
+    return 0;
+}
+
+puObject *fgPopup::getActiveInputField(puObject *object)
+{
+    puObject *ret;
+    if(object->getType() & PUCLASS_GROUP)
+        for (puObject *obj = ((puGroup *)object)->getFirstChild();
+                obj; obj = obj->getNextObject())
+            if ((ret = getActiveInputField(obj)))
+                return ret;
+
+    if (object->getType() & PUCLASS_INPUT && ((puInput *)object)->isAcceptingInput())
+        return object;
+
+    return 0;
+}
+
+/**
+ * Mouse handler.
+ */
 int fgPopup::checkHit(int button, int updown, int x, int y)
 {
     int result = puPopup::checkHit(button, updown, x, y);
@@ -67,19 +153,6 @@ int fgPopup::getHitObjects(puObject *object, int x, int y)
 // Callbacks.
 ////////////////////////////////////////////////////////////////////////
 
-/**
- * User data for a GUI object.
- */
-struct GUIInfo
-{
-    GUIInfo (FGDialog * d);
-    virtual ~GUIInfo ();
-
-    FGDialog * dialog;
-    vector <FGBinding *> bindings;
-};
-
-
 /**
  * Action callback.
  */
@@ -231,25 +304,6 @@ copy_from_pui (puObject * object, SGPropertyNode * node)
 }
 
 
-\f
-////////////////////////////////////////////////////////////////////////
-// Implementation of GUIInfo.
-////////////////////////////////////////////////////////////////////////
-
-GUIInfo::GUIInfo (FGDialog * d)
-    : dialog(d)
-{
-}
-
-GUIInfo::~GUIInfo ()
-{
-    for (unsigned int i = 0; i < bindings.size(); i++) {
-        delete bindings[i];
-        bindings[i] = 0;
-    }
-}
-
-
 \f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of FGDialog.
@@ -406,6 +460,9 @@ FGDialog::display (SGPropertyNode * props)
 puObject *
 FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
 {
+    if (props->getBoolValue("hide"))
+        return 0;
+
     bool presetSize = props->hasValue("width") && props->hasValue("height");
     int width = props->getIntValue("width", parentWidth);
     int height = props->getIntValue("height", parentHeight);
@@ -627,6 +684,7 @@ FGDialog::setupObject (puObject * object, SGPropertyNode * props)
     vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
     if (bindings.size() > 0) {
         GUIInfo * info = new GUIInfo(this);
+        info->key = props->getIntValue("keynum", -1);
 
         for (unsigned int i = 0; i < bindings.size(); i++) {
             unsigned int j = 0;
@@ -667,41 +725,45 @@ void
 FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
 {
     string type = props->getName();
-    FGColor c(_gui->getColor("background"));
-    c.merge(_gui->getColor(type));
-    c.merge(props->getNode("color"));
-    if (c.isValid())
-        object->setColourScheme(c.red(), c.green(), c.blue(), c.alpha());
+    if (type == "")
+        type = "dialog";
+
+    FGColor *c = new FGColor(_gui->getColor("background"));
+    c->merge(_gui->getColor(type));
+    c->merge(props->getNode("color"));
+    if (c->isValid())
+        object->setColourScheme(c->red(), c->green(), c->blue(), c->alpha());
 
-    const int numcol = 6;
     const struct {
         int mask;
         int id;
         const char *name;
         const char *cname;
-    } pucol[numcol] = {
-        BACKGROUND, PUCOL_BACKGROUND, "background", "color-background",
-        FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground",
-        HIGHLIGHT,  PUCOL_HIGHLIGHT,  "highlight",  "color-highlight",
-        LABEL,      PUCOL_LABEL,      "label",      "color-label",
-        LEGEND,     PUCOL_LEGEND,     "legend",     "color-legend",
-        MISC,       PUCOL_MISC,       "misc",       "color-misc",
+    } pucol[] = {
+        { BACKGROUND, PUCOL_BACKGROUND, "background", "color-background" },
+        { FOREGROUND, PUCOL_FOREGROUND, "foreground", "color-foreground" },
+        { HIGHLIGHT,  PUCOL_HIGHLIGHT,  "highlight",  "color-highlight" },
+        { LABEL,      PUCOL_LABEL,      "label",      "color-label" },
+        { LEGEND,     PUCOL_LEGEND,     "legend",     "color-legend" },
+        { MISC,       PUCOL_MISC,       "misc",       "color-misc" }
     };
 
+    const int numcol = sizeof(pucol) / sizeof(pucol[0]);
+
     for (int i = 0; i < numcol; i++) {
         bool dirty = false;
-        c.clear();
-        c.setAlpha(1.0);
+        c->clear();
+        c->setAlpha(1.0);
 
-        dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name));
+        dirty |= c->merge(_gui->getColor(type + '-' + pucol[i].name));
         if (which & pucol[i].mask)
-            dirty |= c.merge(props->getNode("color"));
+            dirty |= c->merge(props->getNode("color"));
 
-        if ((pucol[i].mask == LABEL) && !c.isValid())
-            dirty |= c.merge(_gui->getColor("label"));
+        if ((pucol[i].mask == LABEL) && !c->isValid())
+            dirty |= c->merge(_gui->getColor("label"));
 
-        if (c.isValid() && dirty)
-            object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha());
+        if (c->isValid() && dirty)
+            object->setColor(pucol[i].id, c->red(), c->green(), c->blue(), c->alpha());
     }
 }