# include "config.h"
#endif
-#include <stdlib.h> // atof()
-
#include <Input/input.hxx>
#include <Scripting/NasalSys.hxx>
#include "dialog.hxx"
#include "new_gui.hxx"
-
#include "AirportList.hxx"
#include "property_list.hxx"
#include "layout.hxx"
puObject *fgPopup::getKeyObject(puObject *object, int key)
{
puObject *ret;
- if(object->getType() & PUCLASS_GROUP)
+ if (object->getType() & PUCLASS_GROUP)
for (puObject *obj = ((puGroup *)object)->getFirstChild();
obj; obj = obj->getNextObject())
if ((ret = getKeyObject(obj, key)))
puObject *fgPopup::getActiveInputField(puObject *object)
{
puObject *ret;
- if(object->getType() & PUCLASS_GROUP)
+ if (object->getType() & PUCLASS_GROUP)
for (puObject *obj = ((puGroup *)object)->getFirstChild();
obj; obj = obj->getNextObject())
if ((ret = getActiveInputField(obj)))
{
int result = puPopup::checkHit(button, updown, x, y);
- if ( !_draggable)
+ if (!_draggable)
return result;
// This is annoying. We would really want a true result from the
// intersection test (again) to make sure we don't start a drag
// when inside controls.
- if(updown == PU_DOWN && !_dragging) {
- if(!result)
+ if (updown == PU_DOWN && !_dragging) {
+ if (!result)
return 0;
int hit = getHitObjects(this, x, y);
- if(hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT))
+ if (hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT))
return result;
int px, py;
_dragging = true;
_dX = px - x;
_dY = py - y;
- } else if(updown == PU_DRAG && _dragging) {
+ } else if (updown == PU_DRAG && _dragging) {
setPosition(x + _dX, y + _dY);
} else {
_dragging = false;
return 0;
int type = 0;
- if(object->getType() & PUCLASS_GROUP)
+ if (object->getType() & PUCLASS_GROUP)
for (puObject *obj = ((puGroup *)object)->getFirstChild();
obj; obj = obj->getNextObject())
type |= getHitObjects(obj, x, y);
int cx, cy, cw, ch;
object->getAbsolutePosition(&cx, &cy);
object->getSize(&cw, &ch);
- if(x >= cx && x < cx + cw && y >= cy && y < cy + ch)
+ if (x >= cx && x < cx + cw && y >= cy && y < cy + ch)
type |= object->getType();
return type;
}
// from properties.
if (object->getType() & PUCLASS_TEXT) {
GUIInfo *info = (GUIInfo *)object->getUserData();
- if (info && info->fmt_string) {
+ if (info && info->fmt_string)
object->setLabel(info->format(node));
- } else {
+ else
object->setLabel(node->getStringValue());
- }
return;
}
PropertyObject* po = new PropertyObject(name, object, node);
_propertyObjects.push_back(po);
- if(props->getBoolValue("live"))
+ if (props->getBoolValue("live"))
_liveObjects.push_back(po);
}
info->text = new char[FORMAT_BUFSIZE + 1];
info->fmt_string = new char[strlen(format) + 1];
strcpy(info->fmt_string, format);
+ } else {
+ SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
+ << format << '\'');
}
}
}
#include <simgear/compiler.h>
+#include <sstream>
#include STL_IOMANIP
#include STL_STRING
SG_USING_STD(string);
static string getValueTypeString(const SGPropertyNode *node)
{
string result;
- assert(node);
SGPropertyNode::Type type = node->getType();
if (type == SGPropertyNode::UNSPECIFIED)
static void dumpProperties(const SGPropertyNode *node)
{
- cout << node->getPath() << "/" << endl;
+ cout << node->getPath() << '/' << endl;
for (int i = 0; i < node->nChildren(); i++) {
const SGPropertyNode *c = node->getChild(i);
SGPropertyNode::Type type = c->getType();
_return(0),
_entries(0),
_num_entries(0),
- _flags(false)
+ _verbose(false)
{
_list_box->setUserData(this);
if (prop_list->_dot_files && (selected < 2)) {
if (!strcmp(src, ".")) {
if (mod_ctrl)
- prop_list->toggleFlags();
+ prop_list->toggleVerbosity();
else if (mod_shift)
dumpProperties(prop_list->_curr);
selected -= 2;
SGPropertyNode_ptr child = prop_list->_children[selected].node;
- assert(child);
// check if it's a directory
if (child->nChildren()) {
// Make lists of the children's names, values, etc.
for (i = 0; i < _num_children; i++, pi++) {
- SGPropertyNode *child = _children[i].node;
-
- if (child->nChildren() > 0) {
- stdString name = stdString(child->getDisplayName(true)) + '/';
- _entries[pi] = new char[name.size() + 1];
- strcpy(_entries[pi], name.c_str());
-
- } else {
- _entries[pi] = 0; // make it delete-able
- updateTextForEntry(i);
- _children[i].setListener(this);
- }
+ _children[i].text = &_entries[pi];
+ _entries[pi] = 0; // make it deletable
+ updateTextForEntry(_children[i]);
+ _children[i].setListener(this);
}
_entries[_num_entries] = 0;
}
-void PropertyList::updateTextForEntry(int index)
+void PropertyList::updateTextForEntry(NodeData& data)
{
- assert((index >= 0) && (index < _num_children));
- SGPropertyNode_ptr node = _children[index].node;
-
+ SGPropertyNode *node = data.node;
stdString name = node->getDisplayName(true);
stdString type = getValueTypeString(node);
stdString value = node->getStringValue();
- if (node->getType() == SGPropertyNode::STRING
- || node->getType() == SGPropertyNode::UNSPECIFIED)
- sanitize(value);
-
- stdString line = name + " = '" + value + "' (" + type;
-
- if (_flags) {
- stdString ext;
- if (!node->getAttribute(SGPropertyNode::READ))
- ext += 'r';
- if (!node->getAttribute(SGPropertyNode::WRITE))
- ext += 'w';
- if (node->getAttribute(SGPropertyNode::TRACE_READ))
- ext += 'R';
- if (node->getAttribute(SGPropertyNode::TRACE_WRITE))
- ext += 'W';
- if (node->getAttribute(SGPropertyNode::ARCHIVE))
- ext += 'A';
- if (node->getAttribute(SGPropertyNode::USERARCHIVE))
- ext += 'U';
- if (node->isTied())
- ext += 'T';
- if (ext.size())
- line += ", " + ext;
+ std::ostringstream line;
+ line << name;
+
+ int children = node->nChildren();
+ if (children)
+ line << '/';
+
+ if (!children || (_verbose && node->hasValue())) {
+ if (node->getType() == SGPropertyNode::STRING
+ || node->getType() == SGPropertyNode::UNSPECIFIED)
+ sanitize(value);
+
+ line << " = '" << value << "' (" << type;
+
+ if (_verbose) {
+ stdString ext;
+ if (!node->getAttribute(SGPropertyNode::READ))
+ ext += 'r';
+ if (!node->getAttribute(SGPropertyNode::WRITE))
+ ext += 'w';
+ if (node->getAttribute(SGPropertyNode::TRACE_READ))
+ ext += 'R';
+ if (node->getAttribute(SGPropertyNode::TRACE_WRITE))
+ ext += 'W';
+ if (node->getAttribute(SGPropertyNode::ARCHIVE))
+ ext += 'A';
+ if (node->getAttribute(SGPropertyNode::USERARCHIVE))
+ ext += 'U';
+ if (node->isTied())
+ ext += 'T';
+
+ if (!ext.empty())
+ line << ", " << ext;
+
+ int num = node->nListeners();
+ if (data.listener)
+ num--;
+ if (lst)
+ line << ", L" << num;
+ }
+ line << ')';
}
- line += ')';
-
- if (line.size() >= PUSTRING_MAX)
- line.resize(PUSTRING_MAX - 1);
-
- if (_dot_files)
- index += 2;
+ stdString out = line.str();
+ if (out.size() >= PUSTRING_MAX)
+ out.resize(PUSTRING_MAX - 1);
- delete[] _entries[index];
- _entries[index] = new char[line.size() + 1];
- strcpy(_entries[index], line.c_str());
+ delete[] *data.text;
+ *data.text = new char[out.size() + 1];
+ strcpy(*data.text, out.c_str());
}
{
for (int i = 0; i < _num_children; i++)
if (_children[i].node == nd) {
- updateTextForEntry(i);
+ updateTextForEntry(_children[i]);
return;
}
}
void setCurrent(SGPropertyNode *p);
SGPropertyNode *getCurrent() const { return _curr; }
void publish(SGPropertyNode *p) { _return = p; invokeCallback(); }
- void toggleFlags() { _flags = !_flags; }
+ void toggleVerbosity() { _verbose = !_verbose; }
// overridden plib pui methods
virtual char *getListStringValue() { return (char *)(_return ? _return->getPath(true) : ""); }
virtual void valueChanged(SGPropertyNode *node);
private:
- // update the text string in the puList using the given node and
- // updating the requested offset. The value of dotFiles is taken
- // into account before the index is applied, i.e this should be
- // an index into 'children'
- void updateTextForEntry(int index);
- void delete_arrays();
- static void handle_select(puObject *b);
- static int nodeNameCompare(const void *, const void *);
-
- SGPropertyNode_ptr _curr;
- SGPropertyNode_ptr _return;
-
- char **_entries;
- int _num_entries;
-
struct NodeData {
NodeData() : listener(0) {}
~NodeData() {
}
SGPropertyNode_ptr node;
SGPropertyChangeListener *listener;
+ char **text;
};
+
+ // update the text string in the puList using the given node and
+ // updating the requested offset.
+ void updateTextForEntry(NodeData&);
+ void delete_arrays();
+ static void handle_select(puObject *b);
+ static int nodeNameCompare(const void *, const void *);
+
+ SGPropertyNode_ptr _curr;
+ SGPropertyNode_ptr _return;
+
+ char **_entries;
+ int _num_entries;
+
NodeData *_children;
int _num_children;
bool _dot_files; // . and .. pseudo-dirs currently shown?
- bool _flags; // show SGPropertyNode flags
+ bool _verbose; // show SGPropertyNode flags
};