]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/FGPUIMenuBar.cxx
Support for multiple data dirs.
[flightgear.git] / src / GUI / FGPUIMenuBar.cxx
index a7d8ba0eb4c81e14cd41a9bdcf48b92885f86ef3..b610caf01a67d08d6fc9c177996132117525d716 100644 (file)
@@ -10,6 +10,7 @@
 #include <simgear/props/props_io.hxx>
 
 #include <Main/globals.hxx>
+#include <Main/locale.hxx>
 #include <Main/fg_props.hxx>
 
 #include "new_gui.hxx"
@@ -75,8 +76,6 @@ menu_callback (puObject * object)
     mb->fireItem(object);
 }
 
-
-\f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of FGPUIMenuBar.
 ////////////////////////////////////////////////////////////////////////
@@ -96,7 +95,8 @@ FGPUIMenuBar::~FGPUIMenuBar ()
 void
 FGPUIMenuBar::init ()
 {
-    delete _menuBar;            // FIXME: check if PUI owns the pointer
+    destroy_menubar();
+  
     make_menubar();
                                 // FIXME: temporary commands to get at
                                 // old, hard-coded dialogs.
@@ -139,7 +139,15 @@ FGPUIMenuBar::fireItem (puObject * item)
 void
 FGPUIMenuBar::make_menu (SGPropertyNode * node)
 {
-    const char * name = strdup(node->getStringValue("label"));
+    string s = getLocalizedLabel(node);
+
+    // hack: map at least some UTF-8 characters to Latin1, since FG fonts are
+    // Latin1 (or plain ASCII, which is a subset). This hack can be removed once
+    // the PLIB/OSG port is complete (OSG has full UTF-8 support! :) ).
+    FGLocale::utf8toLatin1(s);
+
+    const char* name = strdup(s.c_str());
+
     vector<SGPropertyNode_ptr> item_nodes = node->getChildren("item");
 
     int array_size = item_nodes.size();
@@ -152,13 +160,24 @@ FGPUIMenuBar::make_menu (SGPropertyNode * node)
          i++, j--) {
 
                                 // Set up the PUI entries for this item
-        items[j] = strdup((char *)item_nodes[i]->getStringValue("label"));
+        string label = getLocalizedLabel(item_nodes[i]);
+        FGLocale::utf8toLatin1(label);
+
+        // append the keyboard hint to the menu entry
+        const char* key = item_nodes[i]->getStringValue("key", 0);
+        if (key)
+        {
+            label.append("           <");
+            label.append(key);
+            label.append(">");
+        }
+        items[j] = strdup(label.c_str());
         callbacks[j] = menu_callback;
 
                                 // Load all the bindings for this item
         vector<SGPropertyNode_ptr> bindings = item_nodes[i]->getChildren("binding");
         SGPropertyNode * dest = fgGetNode("/sim/bindings/menu", true);
-
+      
         for (unsigned int k = 0; k < bindings.size(); k++) {
             unsigned int m = 0;
             SGPropertyNode_ptr binding;
@@ -242,11 +261,14 @@ FGPUIMenuBar::destroy_menubar ()
                                 // plib.
     SG_LOG(SG_GENERAL, SG_BULK, "Deleting char arrays");
     for (i = 0; i < _char_arrays.size(); i++) {
-        for (int j = 0; _char_arrays[i][j] != 0; j++)
+        for (int j = 0; _char_arrays[i][j] != 0; j++) {
             free(_char_arrays[i][j]); // added with strdup
+            _char_arrays[i][j] = 0;
+        }
         delete[] _char_arrays[i];
+        _char_arrays[i] = 0;
     }
-
+  
                                 // Delete all the callback arrays
                                 // we were forced to keep around for
                                 // plib.
@@ -263,6 +285,10 @@ FGPUIMenuBar::destroy_menubar ()
             delete it->second[i];
     }
 
+    _menuBar = NULL;
+    _bindings.clear();
+    _char_arrays.clear();
+    _callback_arrays.clear();
     SG_LOG(SG_GENERAL, SG_BULK, "Done.");
 }
 
@@ -314,7 +340,9 @@ FGPUIMenuBar::make_object_map(SGPropertyNode * node)
     }
 }
 
-struct EnabledListener : SGPropertyChangeListener {
+namespace { 
+  
+  struct EnabledListener : SGPropertyChangeListener {
     void valueChanged(SGPropertyNode *node) {
         NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
         if (!gui)
@@ -325,6 +353,8 @@ struct EnabledListener : SGPropertyChangeListener {
     }
 };
 
+} // of anonymous namespace
+
 void
 FGPUIMenuBar::add_enabled_listener(SGPropertyNode * node)
 {