2003-01-18 15:16:34 +00:00
|
|
|
|
// dialog.cxx: implementation of an XML-configurable dialog box.
|
|
|
|
|
|
2006-02-18 13:58:09 +00:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
#include <Input/input.hxx>
|
2006-03-08 10:44:46 +00:00
|
|
|
|
#include <Scripting/NasalSys.hxx>
|
2009-01-10 21:58:26 +00:00
|
|
|
|
#include <Main/fg_os.hxx>
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
#include "dialog.hxx"
|
|
|
|
|
#include "new_gui.hxx"
|
2003-11-27 23:41:00 +00:00
|
|
|
|
#include "AirportList.hxx"
|
2006-05-22 14:35:39 +00:00
|
|
|
|
#include "property_list.hxx"
|
2004-05-12 15:36:07 +00:00
|
|
|
|
#include "layout.hxx"
|
2003-11-27 23:41:00 +00:00
|
|
|
|
|
2006-05-22 16:14:50 +00:00
|
|
|
|
|
2007-04-02 17:20:05 +00:00
|
|
|
|
enum format_type { f_INVALID, f_INT, f_LONG, f_FLOAT, f_DOUBLE, f_STRING };
|
2007-04-02 12:12:23 +00:00
|
|
|
|
static const int FORMAT_BUFSIZE = 255;
|
2009-02-10 22:14:13 +00:00
|
|
|
|
static const int RESIZE_MARGIN = 7;
|
|
|
|
|
|
2007-04-02 12:12:23 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2007-04-02 15:42:45 +00:00
|
|
|
|
* Makes sure the format matches '%[ -+#]?\d*(\.\d*)?(l?[df]|s)', with
|
|
|
|
|
* only one number or string placeholder and otherwise arbitrary prefix
|
|
|
|
|
* and postfix containing only quoted percent signs (%%).
|
2007-04-02 12:12:23 +00:00
|
|
|
|
*/
|
2007-04-02 15:42:45 +00:00
|
|
|
|
static format_type
|
|
|
|
|
validate_format(const char *f)
|
2007-04-02 12:12:23 +00:00
|
|
|
|
{
|
2007-04-02 15:42:45 +00:00
|
|
|
|
bool l = false;
|
|
|
|
|
format_type type;
|
2007-04-02 12:12:23 +00:00
|
|
|
|
for (; *f; f++) {
|
|
|
|
|
if (*f == '%') {
|
|
|
|
|
if (f[1] == '%')
|
|
|
|
|
f++;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (*f++ != '%')
|
2007-04-02 17:20:05 +00:00
|
|
|
|
return f_INVALID;
|
2007-07-03 17:26:54 +00:00
|
|
|
|
while (*f == ' ' || *f == '+' || *f == '-' || *f == '#' || *f == '0')
|
2007-04-02 12:12:23 +00:00
|
|
|
|
f++;
|
|
|
|
|
while (*f && isdigit(*f))
|
|
|
|
|
f++;
|
|
|
|
|
if (*f == '.') {
|
|
|
|
|
f++;
|
|
|
|
|
while (*f && isdigit(*f))
|
|
|
|
|
f++;
|
|
|
|
|
}
|
2007-04-02 15:42:45 +00:00
|
|
|
|
|
2007-04-02 12:12:23 +00:00
|
|
|
|
if (*f == 'l')
|
|
|
|
|
l = true, f++;
|
|
|
|
|
|
2007-04-02 15:42:45 +00:00
|
|
|
|
if (*f == 'd') {
|
2007-04-02 17:20:05 +00:00
|
|
|
|
type = l ? f_LONG : f_INT;
|
2007-04-02 15:42:45 +00:00
|
|
|
|
} else if (*f == 'f')
|
2007-04-02 17:20:05 +00:00
|
|
|
|
type = l ? f_DOUBLE : f_FLOAT;
|
2007-04-02 12:12:23 +00:00
|
|
|
|
else if (*f == 's') {
|
|
|
|
|
if (l)
|
2007-04-02 17:20:05 +00:00
|
|
|
|
return f_INVALID;
|
|
|
|
|
type = f_STRING;
|
2007-04-02 12:12:23 +00:00
|
|
|
|
} else
|
2007-04-02 17:20:05 +00:00
|
|
|
|
return f_INVALID;
|
2007-04-02 12:12:23 +00:00
|
|
|
|
|
|
|
|
|
for (++f; *f; f++) {
|
|
|
|
|
if (*f == '%') {
|
|
|
|
|
if (f[1] == '%')
|
|
|
|
|
f++;
|
|
|
|
|
else
|
2007-04-02 17:20:05 +00:00
|
|
|
|
return f_INVALID;
|
2007-04-02 12:12:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-02 15:42:45 +00:00
|
|
|
|
return type;
|
2007-04-02 12:12:23 +00:00
|
|
|
|
}
|
2006-05-22 16:14:50 +00:00
|
|
|
|
|
|
|
|
|
|
2005-11-02 13:52:01 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of GUIInfo.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2005-11-02 13:11:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* User data for a GUI object.
|
|
|
|
|
*/
|
|
|
|
|
struct GUIInfo
|
|
|
|
|
{
|
2009-01-12 17:30:58 +00:00
|
|
|
|
GUIInfo(FGDialog *d);
|
2007-04-02 15:42:45 +00:00
|
|
|
|
virtual ~GUIInfo();
|
2008-12-18 20:18:50 +00:00
|
|
|
|
void apply_format(SGPropertyNode *);
|
2005-11-02 13:11:19 +00:00
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog *dialog;
|
2009-01-10 21:58:26 +00:00
|
|
|
|
SGPropertyNode_ptr node;
|
2007-01-04 13:22:27 +00:00
|
|
|
|
vector <SGBinding *> bindings;
|
2005-11-02 13:11:19 +00:00
|
|
|
|
int key;
|
2008-12-18 20:18:50 +00:00
|
|
|
|
string label, legend, text, format;
|
2007-04-02 15:42:45 +00:00
|
|
|
|
format_type fmt_type;
|
2005-11-02 13:11:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
GUIInfo::GUIInfo (FGDialog *d) :
|
2008-12-18 20:18:50 +00:00
|
|
|
|
dialog(d),
|
|
|
|
|
key(-1),
|
|
|
|
|
fmt_type(f_INVALID)
|
2005-11-02 13:52:01 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2005-11-02 13:11:19 +00:00
|
|
|
|
|
2005-11-02 13:52:01 +00:00
|
|
|
|
GUIInfo::~GUIInfo ()
|
|
|
|
|
{
|
|
|
|
|
for (unsigned int i = 0; i < bindings.size(); i++) {
|
|
|
|
|
delete bindings[i];
|
|
|
|
|
bindings[i] = 0;
|
|
|
|
|
}
|
2007-04-02 15:42:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-18 20:18:50 +00:00
|
|
|
|
void GUIInfo::apply_format(SGPropertyNode *n)
|
2007-04-02 15:42:45 +00:00
|
|
|
|
{
|
2008-12-18 20:18:50 +00:00
|
|
|
|
char buf[FORMAT_BUFSIZE + 1];
|
2007-04-02 17:20:05 +00:00
|
|
|
|
if (fmt_type == f_INT)
|
2008-12-18 20:18:50 +00:00
|
|
|
|
snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getIntValue());
|
2007-04-02 17:20:05 +00:00
|
|
|
|
else if (fmt_type == f_LONG)
|
2008-12-18 20:18:50 +00:00
|
|
|
|
snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getLongValue());
|
2007-04-02 17:20:05 +00:00
|
|
|
|
else if (fmt_type == f_FLOAT)
|
2008-12-18 20:18:50 +00:00
|
|
|
|
snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getFloatValue());
|
2007-04-02 17:20:05 +00:00
|
|
|
|
else if (fmt_type == f_DOUBLE)
|
2008-12-18 20:18:50 +00:00
|
|
|
|
snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getDoubleValue());
|
2007-04-02 15:42:45 +00:00
|
|
|
|
else
|
2008-12-18 20:18:50 +00:00
|
|
|
|
snprintf(buf, FORMAT_BUFSIZE, format.c_str(), n->getStringValue());
|
2007-04-02 15:42:45 +00:00
|
|
|
|
|
2008-12-18 20:18:50 +00:00
|
|
|
|
buf[FORMAT_BUFSIZE] = '\0';
|
|
|
|
|
text = buf;
|
2005-11-02 13:52:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
|
2005-11-02 13:52:01 +00:00
|
|
|
|
|
2005-11-02 13:11:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
|
2005-11-05 18:41:43 +00:00
|
|
|
|
// invokeCallback() isn't enough; we need to simulate a mouse button press
|
|
|
|
|
object->checkHit(PU_LEFT_BUTTON, PU_DOWN,
|
|
|
|
|
(object->getABox()->min[0] + object->getABox()->max[0]) / 2,
|
|
|
|
|
(object->getABox()->min[1] + object->getABox()->max[1]) / 2);
|
|
|
|
|
object->checkHit(PU_LEFT_BUTTON, PU_UP,
|
|
|
|
|
(object->getABox()->min[0] + object->getABox()->max[0]) / 2,
|
|
|
|
|
(object->getABox()->min[1] + object->getABox()->max[1]) / 2);
|
2005-11-02 13:11:19 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puObject *fgPopup::getKeyObject(puObject *object, int key)
|
|
|
|
|
{
|
|
|
|
|
puObject *ret;
|
2007-05-07 14:29:40 +00:00
|
|
|
|
if (object->getType() & PUCLASS_GROUP)
|
2005-11-02 13:11:19 +00:00
|
|
|
|
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)
|
2005-11-05 18:41:43 +00:00
|
|
|
|
return object;
|
2005-11-02 13:11:19 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puObject *fgPopup::getActiveInputField(puObject *object)
|
|
|
|
|
{
|
2005-11-03 20:15:05 +00:00
|
|
|
|
puObject *ret;
|
2007-05-07 14:29:40 +00:00
|
|
|
|
if (object->getType() & PUCLASS_GROUP)
|
2005-11-02 13:11:19 +00:00
|
|
|
|
for (puObject *obj = ((puGroup *)object)->getFirstChild();
|
|
|
|
|
obj; obj = obj->getNextObject())
|
2005-11-03 20:15:05 +00:00
|
|
|
|
if ((ret = getActiveInputField(obj)))
|
|
|
|
|
return ret;
|
2005-11-02 13:11:19 +00:00
|
|
|
|
|
2009-02-10 09:46:30 +00:00
|
|
|
|
if (object->getType() & (PUCLASS_INPUT|PUCLASS_LARGEINPUT)
|
|
|
|
|
&& ((puInput *)object)->isAcceptingInput())
|
2005-11-02 13:11:19 +00:00
|
|
|
|
return object;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mouse handler.
|
|
|
|
|
*/
|
2004-05-03 00:40:50 +00:00
|
|
|
|
int fgPopup::checkHit(int button, int updown, int x, int y)
|
|
|
|
|
{
|
2009-01-24 23:22:58 +00:00
|
|
|
|
int result = 0;
|
2009-01-11 00:28:25 +00:00
|
|
|
|
if (updown != PU_DRAG && !_dragging)
|
2009-01-10 21:58:26 +00:00
|
|
|
|
result = puPopup::checkHit(button, updown, x, y);
|
2004-05-03 00:40:50 +00:00
|
|
|
|
|
2007-05-07 14:29:40 +00:00
|
|
|
|
if (!_draggable)
|
2005-05-02 12:14:12 +00:00
|
|
|
|
return result;
|
|
|
|
|
|
2004-05-03 00:40:50 +00:00
|
|
|
|
// This is annoying. We would really want a true result from the
|
|
|
|
|
// superclass to indicate "handled by child object", but all it
|
|
|
|
|
// tells us is that the pointer is inside the dialog. So do the
|
|
|
|
|
// intersection test (again) to make sure we don't start a drag
|
2004-05-14 17:16:35 +00:00
|
|
|
|
// when inside controls.
|
2005-03-24 13:41:43 +00:00
|
|
|
|
|
2007-05-07 14:29:40 +00:00
|
|
|
|
if (updown == PU_DOWN && !_dragging) {
|
|
|
|
|
if (!result)
|
2005-03-24 13:41:43 +00:00
|
|
|
|
return 0;
|
2009-01-12 17:30:58 +00:00
|
|
|
|
int global_drag = fgGetKeyModifiers() & KEYMOD_SHIFT;
|
|
|
|
|
int global_resize = fgGetKeyModifiers() & KEYMOD_CTRL;
|
2005-03-24 13:41:43 +00:00
|
|
|
|
|
|
|
|
|
int hit = getHitObjects(this, x, y);
|
2009-01-17 21:05:22 +00:00
|
|
|
|
if (hit & PUCLASS_LIST) // ctrl-click in property browser (toggle bool)
|
|
|
|
|
return result;
|
2009-01-20 14:23:24 +00:00
|
|
|
|
if (!global_resize && hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
|
|
|
|
|
|PUCLASS_LARGEINPUT|PUCLASS_SCROLLBAR))
|
2009-01-11 15:59:28 +00:00
|
|
|
|
return result;
|
2004-05-03 00:40:50 +00:00
|
|
|
|
|
2009-01-10 21:58:26 +00:00
|
|
|
|
getPosition(&_dlgX, &_dlgY);
|
|
|
|
|
getSize(&_dlgW, &_dlgH);
|
2009-01-11 15:59:28 +00:00
|
|
|
|
_start_cursor = fgGetMouseCursor();
|
2004-05-03 00:40:50 +00:00
|
|
|
|
_dragging = true;
|
2009-01-10 21:58:26 +00:00
|
|
|
|
_startX = x;
|
|
|
|
|
_startY = y;
|
|
|
|
|
|
2009-01-11 15:59:28 +00:00
|
|
|
|
// check and prepare for resizing
|
|
|
|
|
static const int cursor[] = {
|
|
|
|
|
MOUSE_CURSOR_POINTER, MOUSE_CURSOR_LEFTSIDE, MOUSE_CURSOR_RIGHTSIDE, 0,
|
|
|
|
|
MOUSE_CURSOR_TOPSIDE, MOUSE_CURSOR_TOPLEFT, MOUSE_CURSOR_TOPRIGHT, 0,
|
|
|
|
|
MOUSE_CURSOR_BOTTOMSIDE, MOUSE_CURSOR_BOTTOMLEFT, MOUSE_CURSOR_BOTTOMRIGHT, 0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_resizing = 0;
|
2009-01-18 08:27:58 +00:00
|
|
|
|
if (!global_drag && _resizable) {
|
2009-02-10 22:14:13 +00:00
|
|
|
|
int hmargin = global_resize ? _dlgW / 3 : RESIZE_MARGIN;
|
|
|
|
|
int vmargin = global_resize ? _dlgH / 3 : RESIZE_MARGIN;
|
2009-01-11 15:59:28 +00:00
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
if (y - _dlgY < vmargin)
|
|
|
|
|
_resizing |= BOTTOM;
|
|
|
|
|
else if (_dlgY + _dlgH - y < vmargin)
|
|
|
|
|
_resizing |= TOP;
|
2009-01-11 15:59:28 +00:00
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
if (x - _dlgX < hmargin)
|
|
|
|
|
_resizing |= LEFT;
|
|
|
|
|
else if (_dlgX + _dlgW - x < hmargin)
|
|
|
|
|
_resizing |= RIGHT;
|
2009-01-11 15:59:28 +00:00
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
if (!_resizing && global_resize)
|
|
|
|
|
_resizing = BOTTOM|RIGHT;
|
2009-01-11 15:59:28 +00:00
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
_cursor = cursor[_resizing];
|
|
|
|
|
if (_resizing && _resizable)
|
|
|
|
|
fgSetMouseCursor(_cursor);
|
|
|
|
|
}
|
2009-01-11 15:59:28 +00:00
|
|
|
|
|
2007-05-07 14:29:40 +00:00
|
|
|
|
} else if (updown == PU_DRAG && _dragging) {
|
2009-01-11 15:59:28 +00:00
|
|
|
|
if (_resizing) {
|
2009-01-10 21:58:26 +00:00
|
|
|
|
GUIInfo *info = (GUIInfo *)getUserData();
|
2009-01-12 17:30:58 +00:00
|
|
|
|
if (_resizable && info && info->node) {
|
2009-01-11 15:59:28 +00:00
|
|
|
|
int w = _dlgW;
|
|
|
|
|
int h = _dlgH;
|
|
|
|
|
if (_resizing & LEFT)
|
|
|
|
|
w += _startX - x;
|
|
|
|
|
if (_resizing & RIGHT)
|
|
|
|
|
w += x - _startX;
|
|
|
|
|
if (_resizing & TOP)
|
|
|
|
|
h += y - _startY;
|
|
|
|
|
if (_resizing & BOTTOM)
|
|
|
|
|
h += _startY - y;
|
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
int prefw, prefh;
|
|
|
|
|
LayoutWidget wid(info->node);
|
|
|
|
|
wid.calcPrefSize(&prefw, &prefh);
|
2009-01-11 15:59:28 +00:00
|
|
|
|
if (w < prefw)
|
|
|
|
|
w = prefw;
|
|
|
|
|
if (h < prefh)
|
|
|
|
|
h = prefh;
|
|
|
|
|
|
|
|
|
|
int x = _dlgX;
|
|
|
|
|
int y = _dlgY;
|
|
|
|
|
if (_resizing & LEFT)
|
|
|
|
|
x += _dlgW - w;
|
|
|
|
|
if (_resizing & BOTTOM)
|
|
|
|
|
y += _dlgH - h;
|
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
wid.layout(x, y, w, h);
|
2009-01-10 21:58:26 +00:00
|
|
|
|
setSize(w, h);
|
2009-01-11 15:59:28 +00:00
|
|
|
|
setPosition(x, y);
|
2009-01-10 21:58:26 +00:00
|
|
|
|
applySize(static_cast<puObject *>(this));
|
2009-01-12 17:30:58 +00:00
|
|
|
|
getFirstChild()->setSize(w, h); // dialog background puFrame
|
2009-01-10 21:58:26 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
setPosition(x + _dlgX - _startX, y + _dlgY - _startY);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-11 16:37:51 +00:00
|
|
|
|
} else if (_dragging) {
|
2009-01-11 15:59:28 +00:00
|
|
|
|
fgSetMouseCursor(_start_cursor);
|
2009-01-11 16:37:51 +00:00
|
|
|
|
_dragging = false;
|
2004-05-03 00:40:50 +00:00
|
|
|
|
}
|
2005-03-24 13:41:43 +00:00
|
|
|
|
return result;
|
2004-05-03 00:40:50 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2005-03-24 13:41:43 +00:00
|
|
|
|
int fgPopup::getHitObjects(puObject *object, int x, int y)
|
|
|
|
|
{
|
2006-07-10 14:56:07 +00:00
|
|
|
|
if (!object->isVisible())
|
|
|
|
|
return 0;
|
|
|
|
|
|
2005-03-24 13:41:43 +00:00
|
|
|
|
int type = 0;
|
2007-05-07 14:29:40 +00:00
|
|
|
|
if (object->getType() & PUCLASS_GROUP)
|
2005-03-24 13:41:43 +00:00
|
|
|
|
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);
|
2007-05-07 14:29:40 +00:00
|
|
|
|
if (x >= cx && x < cx + cw && y >= cy && y < cy + ch)
|
2005-03-24 13:41:43 +00:00
|
|
|
|
type |= object->getType();
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-10 21:58:26 +00:00
|
|
|
|
void fgPopup::applySize(puObject *object)
|
|
|
|
|
{
|
2009-01-11 15:59:28 +00:00
|
|
|
|
// compound plib widgets use setUserData() for internal purposes, so refuse
|
|
|
|
|
// to descend into anything that has other bits set than the following
|
2009-01-10 21:58:26 +00:00
|
|
|
|
const int validUserData = PUCLASS_VALUE|PUCLASS_OBJECT|PUCLASS_GROUP|PUCLASS_INTERFACE
|
|
|
|
|
|PUCLASS_FRAME|PUCLASS_TEXT|PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
|
|
|
|
|
|PUCLASS_ARROW|PUCLASS_DIAL|PUCLASS_POPUP;
|
|
|
|
|
|
|
|
|
|
int type = object->getType();
|
|
|
|
|
if (type & PUCLASS_GROUP && !(type & ~validUserData))
|
|
|
|
|
for (puObject *obj = ((puGroup *)object)->getFirstChild();
|
|
|
|
|
obj; obj = obj->getNextObject())
|
|
|
|
|
applySize(obj);
|
|
|
|
|
|
|
|
|
|
GUIInfo *info = (GUIInfo *)object->getUserData();
|
|
|
|
|
if (!info)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
SGPropertyNode *n = info->node;
|
|
|
|
|
if (!n) {
|
2009-01-11 15:59:28 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "fgPopup::applySize: no props");
|
2009-01-10 21:58:26 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int x = n->getIntValue("x");
|
|
|
|
|
int y = n->getIntValue("y");
|
|
|
|
|
int w = n->getIntValue("width", 4);
|
|
|
|
|
int h = n->getIntValue("height", 4);
|
|
|
|
|
object->setPosition(x, y);
|
|
|
|
|
object->setSize(w, h);
|
|
|
|
|
}
|
2005-03-24 13:41:43 +00:00
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Callbacks.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Action callback.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2009-01-12 17:30:58 +00:00
|
|
|
|
action_callback (puObject *object)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2009-01-12 17:30:58 +00:00
|
|
|
|
GUIInfo *info = (GUIInfo *)object->getUserData();
|
|
|
|
|
NewGUI *gui = (NewGUI *)globals->get_subsystem("gui");
|
2003-01-20 16:01:16 +00:00
|
|
|
|
gui->setActiveDialog(info->dialog);
|
2003-01-19 23:04:03 +00:00
|
|
|
|
int nBindings = info->bindings.size();
|
|
|
|
|
for (int i = 0; i < nBindings; i++) {
|
2003-01-18 15:16:34 +00:00
|
|
|
|
info->bindings[i]->fire();
|
2003-01-20 16:01:16 +00:00
|
|
|
|
if (gui->getActiveDialog() == 0)
|
2003-01-19 23:04:03 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-01-20 16:01:16 +00:00
|
|
|
|
gui->setActiveDialog(0);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Static helper functions.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copy a property value to a PUI object.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2009-01-12 17:30:58 +00:00
|
|
|
|
copy_to_pui (SGPropertyNode *node, puObject *object)
|
2003-01-19 17:21:38 +00:00
|
|
|
|
{
|
2008-12-18 20:18:50 +00:00
|
|
|
|
GUIInfo *info = (GUIInfo *)object->getUserData();
|
|
|
|
|
if (!info) {
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "dialog: widget without GUIInfo!");
|
|
|
|
|
return; // this can't really happen
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-15 21:41:42 +00:00
|
|
|
|
// Treat puText objects specially, so their "values" can be set
|
|
|
|
|
// from properties.
|
2007-04-02 15:42:45 +00:00
|
|
|
|
if (object->getType() & PUCLASS_TEXT) {
|
2008-12-18 20:18:50 +00:00
|
|
|
|
if (info->fmt_type != f_INVALID)
|
|
|
|
|
info->apply_format(node);
|
2007-05-07 14:29:40 +00:00
|
|
|
|
else
|
2008-12-18 20:18:50 +00:00
|
|
|
|
info->text = node->getStringValue();
|
|
|
|
|
|
|
|
|
|
object->setLabel(info->text.c_str());
|
2004-05-15 21:41:42 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
switch (node->getType()) {
|
|
|
|
|
case SGPropertyNode::BOOL:
|
|
|
|
|
case SGPropertyNode::INT:
|
|
|
|
|
case SGPropertyNode::LONG:
|
|
|
|
|
object->setValue(node->getIntValue());
|
|
|
|
|
break;
|
|
|
|
|
case SGPropertyNode::FLOAT:
|
|
|
|
|
case SGPropertyNode::DOUBLE:
|
|
|
|
|
object->setValue(node->getFloatValue());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2008-12-18 20:18:50 +00:00
|
|
|
|
info->text = node->getStringValue();
|
|
|
|
|
object->setValue(info->text.c_str());
|
2003-01-19 17:21:38 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2009-01-12 17:30:58 +00:00
|
|
|
|
copy_from_pui (puObject *object, SGPropertyNode *node)
|
2003-01-19 17:21:38 +00:00
|
|
|
|
{
|
2004-05-15 21:41:42 +00:00
|
|
|
|
// puText objects are immutable, so should not be copied out
|
2007-04-02 15:42:45 +00:00
|
|
|
|
if (object->getType() & PUCLASS_TEXT)
|
2004-05-15 21:41:42 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
switch (node->getType()) {
|
|
|
|
|
case SGPropertyNode::BOOL:
|
|
|
|
|
case SGPropertyNode::INT:
|
|
|
|
|
case SGPropertyNode::LONG:
|
|
|
|
|
node->setIntValue(object->getIntegerValue());
|
|
|
|
|
break;
|
|
|
|
|
case SGPropertyNode::FLOAT:
|
|
|
|
|
case SGPropertyNode::DOUBLE:
|
|
|
|
|
node->setFloatValue(object->getFloatValue());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2008-03-11 15:58:57 +00:00
|
|
|
|
const char *s = object->getStringValue();
|
|
|
|
|
if (s)
|
|
|
|
|
node->setStringValue(s);
|
2003-01-19 17:21:38 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGDialog.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog::FGDialog (SGPropertyNode *props) :
|
|
|
|
|
_object(0),
|
|
|
|
|
_gui((NewGUI *)globals->get_subsystem("gui")),
|
|
|
|
|
_props(props)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2006-03-08 10:44:46 +00:00
|
|
|
|
_module = string("__dlg:") + props->getStringValue("name", "[unnamed]");
|
|
|
|
|
SGPropertyNode *nasal = props->getNode("nasal");
|
|
|
|
|
if (nasal) {
|
|
|
|
|
_nasal_close = nasal->getNode("close");
|
|
|
|
|
SGPropertyNode *open = nasal->getNode("open");
|
|
|
|
|
if (open) {
|
|
|
|
|
const char *s = open->getStringValue();
|
|
|
|
|
FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
|
2009-03-27 20:04:42 +00:00
|
|
|
|
if (nas)
|
|
|
|
|
nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), props);
|
2006-03-08 10:44:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
display(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGDialog::~FGDialog ()
|
|
|
|
|
{
|
2006-01-29 21:21:56 +00:00
|
|
|
|
int x, y;
|
|
|
|
|
_object->getAbsolutePosition(&x, &y);
|
|
|
|
|
_props->setIntValue("lastx", x);
|
|
|
|
|
_props->setIntValue("lasty", y);
|
2006-03-08 10:44:46 +00:00
|
|
|
|
|
|
|
|
|
FGNasalSys *nas = (FGNasalSys *)globals->get_subsystem("nasal");
|
2009-03-27 20:04:42 +00:00
|
|
|
|
if (nas) {
|
|
|
|
|
if (_nasal_close) {
|
|
|
|
|
const char *s = _nasal_close->getStringValue();
|
|
|
|
|
nas->createModule(_module.c_str(), _module.c_str(), s, strlen(s), _props);
|
|
|
|
|
}
|
|
|
|
|
nas->deleteModule(_module.c_str());
|
2006-03-08 10:44:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 16:01:16 +00:00
|
|
|
|
puDeleteObject(_object);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2003-03-21 20:39:27 +00:00
|
|
|
|
unsigned int i;
|
2003-01-20 16:01:16 +00:00
|
|
|
|
// Delete all the info objects we
|
|
|
|
|
// were forced to keep around because
|
|
|
|
|
// PUI cannot delete its own user data.
|
2003-01-18 15:16:34 +00:00
|
|
|
|
for (i = 0; i < _info.size(); i++) {
|
2003-01-20 16:01:16 +00:00
|
|
|
|
delete (GUIInfo *)_info[i];
|
2003-01-18 15:16:34 +00:00
|
|
|
|
_info[i] = 0;
|
|
|
|
|
}
|
2003-01-20 16:01:16 +00:00
|
|
|
|
// Finally, delete the property links.
|
2003-01-18 15:16:34 +00:00
|
|
|
|
for (i = 0; i < _propertyObjects.size(); i++) {
|
|
|
|
|
delete _propertyObjects[i];
|
|
|
|
|
_propertyObjects[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog::updateValues (const char *objectName)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2006-04-28 12:56:11 +00:00
|
|
|
|
if (objectName && !objectName[0])
|
|
|
|
|
objectName = 0;
|
|
|
|
|
|
2003-03-21 20:39:27 +00:00
|
|
|
|
for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
|
2003-01-19 17:21:38 +00:00
|
|
|
|
const string &name = _propertyObjects[i]->name;
|
2006-04-28 12:14:23 +00:00
|
|
|
|
if (objectName && name != objectName)
|
2006-04-28 11:49:11 +00:00
|
|
|
|
continue;
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2006-04-28 11:49:11 +00:00
|
|
|
|
puObject *obj = _propertyObjects[i]->object;
|
2006-05-21 22:14:18 +00:00
|
|
|
|
if ((obj->getType() & PUCLASS_LIST) && (dynamic_cast<GUI_ID *>(obj)->id & FGCLASS_LIST)) {
|
2006-05-16 12:45:38 +00:00
|
|
|
|
fgList *pl = static_cast<fgList *>(obj);
|
|
|
|
|
pl->update();
|
|
|
|
|
} else
|
2006-04-28 15:55:41 +00:00
|
|
|
|
copy_to_pui(_propertyObjects[i]->node, obj);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog::applyValues (const char *objectName)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2006-04-28 12:56:11 +00:00
|
|
|
|
if (objectName && !objectName[0])
|
|
|
|
|
objectName = 0;
|
|
|
|
|
|
2006-04-28 11:49:11 +00:00
|
|
|
|
for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
|
|
|
|
|
const string &name = _propertyObjects[i]->name;
|
2006-04-28 12:14:23 +00:00
|
|
|
|
if (objectName && name != objectName)
|
2006-04-28 11:49:11 +00:00
|
|
|
|
continue;
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
copy_from_pui(_propertyObjects[i]->object,
|
|
|
|
|
_propertyObjects[i]->node);
|
2006-04-28 11:49:11 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-05-14 17:16:35 +00:00
|
|
|
|
void
|
|
|
|
|
FGDialog::update ()
|
|
|
|
|
{
|
2005-03-24 13:41:43 +00:00
|
|
|
|
for (unsigned int i = 0; i < _liveObjects.size(); i++) {
|
|
|
|
|
puObject *obj = _liveObjects[i]->object;
|
|
|
|
|
if (obj->getType() & PUCLASS_INPUT && ((puInput *)obj)->isAcceptingInput())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
copy_to_pui(_liveObjects[i]->node, obj);
|
|
|
|
|
}
|
2004-05-14 17:16:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
void
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog::display (SGPropertyNode *props)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (_object != 0) {
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
int screenw = globals->get_props()->getIntValue("/sim/startup/xsize");
|
|
|
|
|
int screenh = globals->get_props()->getIntValue("/sim/startup/ysize");
|
|
|
|
|
|
2005-05-17 09:56:52 +00:00
|
|
|
|
bool userx = props->hasValue("x");
|
|
|
|
|
bool usery = props->hasValue("y");
|
2005-05-16 09:05:17 +00:00
|
|
|
|
bool userw = props->hasValue("width");
|
|
|
|
|
bool userh = props->hasValue("height");
|
2004-05-14 17:16:35 +00:00
|
|
|
|
|
2005-07-02 20:49:38 +00:00
|
|
|
|
// Let the layout widget work in the same property subtree.
|
2004-05-12 15:36:07 +00:00
|
|
|
|
LayoutWidget wid(props);
|
2005-05-17 09:56:52 +00:00
|
|
|
|
|
2006-01-27 12:57:13 +00:00
|
|
|
|
SGPropertyNode *fontnode = props->getNode("font");
|
|
|
|
|
if (fontnode) {
|
2006-06-05 20:25:43 +00:00
|
|
|
|
FGFontCache *fc = globals->get_fontcache();
|
2006-01-27 12:57:13 +00:00
|
|
|
|
_font = fc->get(fontnode);
|
|
|
|
|
} else {
|
|
|
|
|
_font = _gui->getDefaultFont();
|
|
|
|
|
}
|
|
|
|
|
wid.setDefaultFont(_font, int(_font->getPointSize()));
|
2005-07-08 20:12:06 +00:00
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
int pw = 0, ph = 0;
|
2005-11-06 23:53:30 +00:00
|
|
|
|
int px, py, savex, savey;
|
2009-01-12 17:30:58 +00:00
|
|
|
|
if (!userw || !userh)
|
2004-05-12 15:36:07 +00:00
|
|
|
|
wid.calcPrefSize(&pw, &ph);
|
|
|
|
|
pw = props->getIntValue("width", pw);
|
|
|
|
|
ph = props->getIntValue("height", ph);
|
2005-11-06 23:53:30 +00:00
|
|
|
|
px = savex = props->getIntValue("x", (screenw - pw) / 2);
|
|
|
|
|
py = savey = props->getIntValue("y", (screenh - ph) / 2);
|
|
|
|
|
|
|
|
|
|
// Negative x/y coordinates are interpreted as distance from the top/right
|
|
|
|
|
// corner rather than bottom/left.
|
2006-02-12 19:43:53 +00:00
|
|
|
|
if (userx && px < 0)
|
2005-11-06 23:53:30 +00:00
|
|
|
|
px = screenw - pw + px;
|
2006-02-12 19:43:53 +00:00
|
|
|
|
if (usery && py < 0)
|
2005-11-06 23:53:30 +00:00
|
|
|
|
py = screenh - ph + py;
|
2005-05-17 09:56:52 +00:00
|
|
|
|
|
|
|
|
|
// Define "x", "y", "width" and/or "height" in the property tree if they
|
|
|
|
|
// are not specified in the configuration file.
|
2004-05-12 15:36:07 +00:00
|
|
|
|
wid.layout(px, py, pw, ph);
|
|
|
|
|
|
2005-05-17 09:56:52 +00:00
|
|
|
|
// Use the dimension and location properties as specified in the
|
|
|
|
|
// configuration file or from the layout widget.
|
2004-05-12 15:36:07 +00:00
|
|
|
|
_object = makeObject(props, screenw, screenh);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2004-05-14 17:16:35 +00:00
|
|
|
|
// Remove automatically generated properties, so the layout looks
|
2005-11-06 23:53:30 +00:00
|
|
|
|
// the same next time around, or restore x and y to preserve negative coords.
|
2009-01-12 17:30:58 +00:00
|
|
|
|
if (userx)
|
2005-11-06 23:53:30 +00:00
|
|
|
|
props->setIntValue("x", savex);
|
|
|
|
|
else
|
|
|
|
|
props->removeChild("x");
|
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
if (usery)
|
2005-11-06 23:53:30 +00:00
|
|
|
|
props->setIntValue("y", savey);
|
|
|
|
|
else
|
|
|
|
|
props->removeChild("y");
|
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
if (!userw) props->removeChild("width");
|
|
|
|
|
if (!userh) props->removeChild("height");
|
2004-05-14 17:16:35 +00:00
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (_object != 0) {
|
|
|
|
|
_object->reveal();
|
|
|
|
|
} else {
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
|
|
|
|
|
<< props->getStringValue("name", "[unnamed]")
|
|
|
|
|
<< " does not contain a proper GUI definition");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puObject *
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog::makeObject (SGPropertyNode *props, int parentWidth, int parentHeight)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2008-08-05 05:27:07 +00:00
|
|
|
|
if (!props->getBoolValue("enabled", true))
|
2005-10-21 17:47:48 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
bool presetSize = props->hasValue("width") && props->hasValue("height");
|
2003-01-18 15:16:34 +00:00
|
|
|
|
int width = props->getIntValue("width", parentWidth);
|
|
|
|
|
int height = props->getIntValue("height", parentHeight);
|
|
|
|
|
int x = props->getIntValue("x", (parentWidth - width) / 2);
|
|
|
|
|
int y = props->getIntValue("y", (parentHeight - height) / 2);
|
2005-07-02 20:49:38 +00:00
|
|
|
|
string type = props->getName();
|
|
|
|
|
|
2007-04-02 12:12:23 +00:00
|
|
|
|
if (type.empty())
|
2003-01-21 02:08:41 +00:00
|
|
|
|
type = "dialog";
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
if (type == "dialog") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puPopup *obj;
|
2005-05-02 12:14:12 +00:00
|
|
|
|
bool draggable = props->getBoolValue("draggable", true);
|
2009-01-10 21:58:26 +00:00
|
|
|
|
bool resizable = props->getBoolValue("resizable", false);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (props->getBoolValue("modal", false))
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj = new puDialogBox(x, y);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
else
|
2009-01-10 21:58:26 +00:00
|
|
|
|
obj = new fgPopup(x, y, resizable, draggable);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupGroup(obj, props, width, height, true);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else if (type == "group") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puGroup *obj = new puGroup(x, y);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupGroup(obj, props, width, height, false);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2005-05-06 11:46:52 +00:00
|
|
|
|
} else if (type == "frame") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puGroup *obj = new puGroup(x, y);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupGroup(obj, props, width, height, true);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2005-07-02 20:49:38 +00:00
|
|
|
|
} else if (type == "hrule" || type == "vrule") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puFrame *obj = new puFrame(x, y, x + width, y + height);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj->setBorderThickness(0);
|
2009-01-10 21:58:26 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, BACKGROUND|FOREGROUND|HIGHLIGHT);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
|
} else if (type == "list") {
|
2006-03-23 23:02:48 +00:00
|
|
|
|
int slider_width = props->getIntValue("slider", 20);
|
2009-01-12 17:30:58 +00:00
|
|
|
|
fgList *obj = new fgList(x, y, x + width, y + height, props, slider_width);
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
2006-03-23 23:02:48 +00:00
|
|
|
|
obj->setSize(width, height);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
|
} else if (type == "airport-list") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
AirportList *obj = new AirportList(x, y, x + width, y + height);
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
|
|
|
|
obj->setSize(width, height);
|
2006-05-22 14:35:39 +00:00
|
|
|
|
setupObject(obj, props);
|
|
|
|
|
setColor(obj, props);
|
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
|
|
} else if (type == "property-list") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
PropertyList *obj = new PropertyList(x, y, x + width, y + height, globals->get_props());
|
2006-05-22 14:35:39 +00:00
|
|
|
|
if (presetSize)
|
|
|
|
|
obj->setSize(width, height);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else if (type == "input") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puInput *obj = new puInput(x, y, x + width, y + height);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else if (type == "text") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puText *obj = new puText(x, y);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-03-26 10:09:34 +00:00
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
// Layed-out objects need their size set, and non-layout ones
|
|
|
|
|
// get a different placement.
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
|
|
|
|
obj->setSize(width, height);
|
|
|
|
|
else
|
|
|
|
|
obj->setLabelPlace(PUPLACE_LABEL_DEFAULT);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setColor(obj, props, LABEL);
|
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-19 17:21:38 +00:00
|
|
|
|
} else if (type == "checkbox") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puButton *obj;
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj = new puButton(x, y, x + width, y + height, PUBUTTON_XCHECK);
|
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
} else if (type == "radio") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puButton *obj;
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj = new puButton(x, y, x + width, y + height, PUBUTTON_CIRCLE);
|
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else if (type == "button") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puButton *obj;
|
|
|
|
|
const char *legend = props->getStringValue("legend", "[none]");
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (props->getBoolValue("one-shot", true))
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj = new puOneShot(x, y, legend);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
else
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj = new puButton(x, y, legend);
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj->setSize(width, height);
|
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-19 23:04:03 +00:00
|
|
|
|
} else if (type == "combo") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
fgComboBox *obj = new fgComboBox(x, y, x + width, y + height, props,
|
|
|
|
|
props->getBoolValue("editable", false));
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-11-09 17:59:53 +00:00
|
|
|
|
setColor(obj, props, EDITFIELD);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-20 16:01:16 +00:00
|
|
|
|
} else if (type == "slider") {
|
|
|
|
|
bool vertical = props->getBoolValue("vertical", false);
|
2009-01-17 21:05:22 +00:00
|
|
|
|
puSlider *obj = new puSlider(x, y, (vertical ? height : width), vertical);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj->setMinValue(props->getFloatValue("min", 0.0));
|
|
|
|
|
obj->setMaxValue(props->getFloatValue("max", 1.0));
|
2009-01-29 17:48:14 +00:00
|
|
|
|
obj->setStepSize(props->getFloatValue("step"));
|
|
|
|
|
obj->setSliderFraction(props->getFloatValue("fraction"));
|
|
|
|
|
#if PLIB_VERSION > 185
|
|
|
|
|
obj->setPageStepSize(props->getFloatValue("pagestep"));
|
|
|
|
|
#endif
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj->setSize(width, height);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-01-20 16:01:16 +00:00
|
|
|
|
} else if (type == "dial") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
puDial *obj = new puDial(x, y, width);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
obj->setMinValue(props->getFloatValue("min", 0.0));
|
|
|
|
|
obj->setMaxValue(props->getFloatValue("max", 1.0));
|
|
|
|
|
obj->setWrap(props->getBoolValue("wrap", true));
|
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2004-09-27 14:40:31 +00:00
|
|
|
|
} else if (type == "textbox") {
|
2006-03-23 23:02:48 +00:00
|
|
|
|
int slider_width = props->getIntValue("slider", 20);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
int wrap = props->getBoolValue("wrap", true);
|
2009-01-29 17:48:14 +00:00
|
|
|
|
#if PLIB_VERSION > 185
|
|
|
|
|
puaLargeInput *obj = new puaLargeInput(x, y,
|
|
|
|
|
x + width, x + height, 11, slider_width, wrap);
|
|
|
|
|
#else
|
|
|
|
|
puaLargeInput *obj = new puaLargeInput(x, y,
|
2009-01-12 17:30:58 +00:00
|
|
|
|
x + width, x + height, 2, slider_width, wrap);
|
2009-01-29 17:48:14 +00:00
|
|
|
|
#endif
|
2005-07-07 21:30:34 +00:00
|
|
|
|
|
2009-01-17 21:05:22 +00:00
|
|
|
|
if (props->getBoolValue("editable"))
|
|
|
|
|
obj->enableInput();
|
|
|
|
|
else
|
|
|
|
|
obj->disableInput();
|
|
|
|
|
|
2006-03-25 07:45:50 +00:00
|
|
|
|
if (presetSize)
|
2006-03-23 23:02:48 +00:00
|
|
|
|
obj->setSize(width, height);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(obj, props, FOREGROUND|LABEL);
|
2009-01-29 18:50:16 +00:00
|
|
|
|
|
|
|
|
|
int top = props->getIntValue("top-line", 0);
|
|
|
|
|
obj->setTopLineInWindow(top < 0 ? unsigned(-1) >> 1 : top);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
|
|
|
|
|
2003-03-29 15:04:52 +00:00
|
|
|
|
} else if (type == "select") {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
fgSelectBox *obj = new fgSelectBox(x, y, x + width, y + height, props);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
setupObject(obj, props);
|
2005-11-09 17:59:53 +00:00
|
|
|
|
setColor(obj, props, EDITFIELD);
|
2005-07-07 21:30:34 +00:00
|
|
|
|
return obj;
|
2003-01-18 15:16:34 +00:00
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog::setupObject (puObject *object, SGPropertyNode *props)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2008-12-18 20:18:50 +00:00
|
|
|
|
GUIInfo *info = new GUIInfo(this);
|
|
|
|
|
object->setUserData(info);
|
|
|
|
|
_info.push_back(info);
|
2004-05-12 15:36:07 +00:00
|
|
|
|
object->setLabelPlace(PUPLACE_CENTERED_RIGHT);
|
2008-12-18 20:18:50 +00:00
|
|
|
|
object->makeReturnDefault(props->getBoolValue("default"));
|
2009-01-10 21:58:26 +00:00
|
|
|
|
info->node = props;
|
2004-05-12 15:36:07 +00:00
|
|
|
|
|
2008-12-18 20:18:50 +00:00
|
|
|
|
if (props->hasValue("legend")) {
|
|
|
|
|
info->legend = props->getStringValue("legend");
|
|
|
|
|
object->setLegend(info->legend.c_str());
|
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2008-12-18 20:18:50 +00:00
|
|
|
|
if (props->hasValue("label")) {
|
|
|
|
|
info->label = props->getStringValue("label");
|
|
|
|
|
object->setLabel(info->label.c_str());
|
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2005-05-06 11:46:52 +00:00
|
|
|
|
if (props->hasValue("border"))
|
|
|
|
|
object->setBorderThickness( props->getIntValue("border", 2) );
|
|
|
|
|
|
2009-01-09 11:58:28 +00:00
|
|
|
|
if (SGPropertyNode *nft = props->getNode("font", false)) {
|
2006-06-05 20:25:43 +00:00
|
|
|
|
FGFontCache *fc = globals->get_fontcache();
|
2006-01-26 21:40:37 +00:00
|
|
|
|
puFont *lfnt = fc->get(nft);
|
|
|
|
|
object->setLabelFont(*lfnt);
|
2009-01-09 11:58:28 +00:00
|
|
|
|
object->setLegendFont(*lfnt);
|
2006-01-27 12:57:13 +00:00
|
|
|
|
} else {
|
|
|
|
|
object->setLabelFont(*_font);
|
2005-05-02 14:45:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-31 16:30:38 +00:00
|
|
|
|
string type = props->getName();
|
|
|
|
|
if (type == "input" && props->getBoolValue("live"))
|
|
|
|
|
object->setDownCallback(action_callback);
|
|
|
|
|
|
|
|
|
|
if (type == "text") {
|
|
|
|
|
const char *format = props->getStringValue("format", 0);
|
|
|
|
|
if (format) {
|
|
|
|
|
info->fmt_type = validate_format(format);
|
|
|
|
|
if (info->fmt_type != f_INVALID)
|
|
|
|
|
info->format = format;
|
|
|
|
|
else
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
|
|
|
|
|
<< format << '\'');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (props->hasValue("property")) {
|
2009-01-12 17:30:58 +00:00
|
|
|
|
const char *name = props->getStringValue("name");
|
2003-01-18 15:16:34 +00:00
|
|
|
|
if (name == 0)
|
|
|
|
|
name = "";
|
2009-01-12 17:30:58 +00:00
|
|
|
|
const char *propname = props->getStringValue("property");
|
2003-01-18 15:16:34 +00:00
|
|
|
|
SGPropertyNode_ptr node = fgGetNode(propname, true);
|
2003-01-19 17:21:38 +00:00
|
|
|
|
copy_to_pui(node, object);
|
2006-04-28 15:55:41 +00:00
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
PropertyObject *po = new PropertyObject(name, object, node);
|
2004-05-14 17:16:35 +00:00
|
|
|
|
_propertyObjects.push_back(po);
|
2007-05-07 14:29:40 +00:00
|
|
|
|
if (props->getBoolValue("live"))
|
2004-05-14 17:16:35 +00:00
|
|
|
|
_liveObjects.push_back(po);
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
SGPropertyNode *dest = fgGetNode("/sim/bindings/gui", true);
|
2005-06-24 13:44:22 +00:00
|
|
|
|
vector<SGPropertyNode_ptr> bindings = props->getChildren("binding");
|
2008-12-18 20:18:50 +00:00
|
|
|
|
if (bindings.size() > 0) {
|
2005-11-02 13:11:19 +00:00
|
|
|
|
info->key = props->getIntValue("keynum", -1);
|
2005-11-05 18:41:43 +00:00
|
|
|
|
if (props->hasValue("key"))
|
|
|
|
|
info->key = getKeyCode(props->getStringValue("key", ""));
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2005-06-24 13:44:22 +00:00
|
|
|
|
for (unsigned int i = 0; i < bindings.size(); i++) {
|
|
|
|
|
unsigned int j = 0;
|
2007-05-30 13:15:14 +00:00
|
|
|
|
SGPropertyNode_ptr binding;
|
2005-06-24 13:44:22 +00:00
|
|
|
|
while (dest->getChild("binding", j))
|
|
|
|
|
j++;
|
|
|
|
|
|
2006-03-08 10:44:46 +00:00
|
|
|
|
const char *cmd = bindings[i]->getStringValue("command");
|
2006-03-08 20:23:31 +00:00
|
|
|
|
if (!strcmp(cmd, "nasal"))
|
2006-03-08 10:44:46 +00:00
|
|
|
|
bindings[i]->setStringValue("module", _module.c_str());
|
|
|
|
|
|
2005-06-24 13:44:22 +00:00
|
|
|
|
binding = dest->getChild("binding", j, true);
|
|
|
|
|
copyProperties(bindings[i], binding);
|
2007-01-04 13:22:27 +00:00
|
|
|
|
info->bindings.push_back(new SGBinding(binding, globals->get_props()));
|
2005-06-24 13:44:22 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
object->setCallback(action_callback);
|
2008-12-18 20:18:50 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog::setupGroup(puGroup *group, SGPropertyNode *props,
|
|
|
|
|
int width, int height, bool makeFrame)
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
|
|
|
|
setupObject(group, props);
|
|
|
|
|
|
2004-05-12 15:36:07 +00:00
|
|
|
|
if (makeFrame) {
|
|
|
|
|
puFrame* f = new puFrame(0, 0, width, height);
|
2005-07-11 08:01:28 +00:00
|
|
|
|
setColor(f, props);
|
2004-05-12 15:36:07 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
|
|
|
|
int nChildren = props->nChildren();
|
|
|
|
|
for (int i = 0; i < nChildren; i++)
|
|
|
|
|
makeObject(props->getChild(i), width, height);
|
|
|
|
|
group->close();
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-04 07:27:17 +00:00
|
|
|
|
void
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog::setColor(puObject *object, SGPropertyNode *props, int which)
|
2005-07-04 07:27:17 +00:00
|
|
|
|
{
|
2005-07-07 21:30:34 +00:00
|
|
|
|
string type = props->getName();
|
2007-04-02 12:12:23 +00:00
|
|
|
|
if (type.empty())
|
2005-07-13 07:05:50 +00:00
|
|
|
|
type = "dialog";
|
2005-11-09 18:23:55 +00:00
|
|
|
|
if (type == "textbox" && props->getBoolValue("editable"))
|
|
|
|
|
type += "-editable";
|
2005-07-13 07:05:50 +00:00
|
|
|
|
|
2008-01-19 18:06:05 +00:00
|
|
|
|
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());
|
2005-07-07 21:30:34 +00:00
|
|
|
|
|
|
|
|
|
const struct {
|
|
|
|
|
int mask;
|
|
|
|
|
int id;
|
|
|
|
|
const char *name;
|
2005-07-11 08:01:28 +00:00
|
|
|
|
const char *cname;
|
2005-11-02 13:11:19 +00:00
|
|
|
|
} pucol[] = {
|
2005-07-13 11:43:00 +00:00
|
|
|
|
{ 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" },
|
2005-11-09 17:59:53 +00:00
|
|
|
|
{ MISC, PUCOL_MISC, "misc", "color-misc" },
|
|
|
|
|
{ EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
|
2005-07-07 21:30:34 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-11-02 13:11:19 +00:00
|
|
|
|
const int numcol = sizeof(pucol) / sizeof(pucol[0]);
|
|
|
|
|
|
2005-07-07 21:30:34 +00:00
|
|
|
|
for (int i = 0; i < numcol; i++) {
|
2005-07-11 08:01:28 +00:00
|
|
|
|
bool dirty = false;
|
2008-01-19 18:06:05 +00:00
|
|
|
|
c.clear();
|
|
|
|
|
c.setAlpha(1.0);
|
2005-07-12 16:48:16 +00:00
|
|
|
|
|
2008-01-19 18:06:05 +00:00
|
|
|
|
dirty |= c.merge(_gui->getColor(type + '-' + pucol[i].name));
|
2005-07-11 08:01:28 +00:00
|
|
|
|
if (which & pucol[i].mask)
|
2008-01-19 18:06:05 +00:00
|
|
|
|
dirty |= c.merge(props->getNode("color"));
|
2005-07-11 08:01:28 +00:00
|
|
|
|
|
2008-01-19 18:06:05 +00:00
|
|
|
|
if ((pucol[i].mask == LABEL) && !c.isValid())
|
|
|
|
|
dirty |= c.merge(_gui->getColor("label"));
|
2005-07-11 08:01:28 +00:00
|
|
|
|
|
2008-01-19 18:06:05 +00:00
|
|
|
|
dirty |= c.merge(props->getNode(pucol[i].cname));
|
allow to not only set a general widget <color>, but also specific element
colors: <color-{{back,fore}ground,highlight,label,legend,misc,editfield}>
<input-misc>, for example, sets the input field cursor color, <input-legend>
the input field text color. (This feature was always planned as part of the
'theming' capabilities, and most code is already in place. Only this line
was apparently fogotten. :-)
2006-04-14 10:17:09 +00:00
|
|
|
|
|
2008-01-19 18:06:05 +00:00
|
|
|
|
if (c.isValid() && dirty)
|
|
|
|
|
object->setColor(pucol[i].id, c.red(), c.green(), c.blue(), c.alpha());
|
2005-07-07 21:30:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-04 07:27:17 +00:00
|
|
|
|
|
2005-11-05 18:41:43 +00:00
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
const char *name;
|
|
|
|
|
int key;
|
|
|
|
|
} keymap[] = {
|
2006-03-01 14:26:17 +00:00
|
|
|
|
{"backspace", 8},
|
2005-11-05 18:41:43 +00:00
|
|
|
|
{"tab", 9},
|
|
|
|
|
{"return", 13},
|
|
|
|
|
{"enter", 13},
|
|
|
|
|
{"esc", 27},
|
|
|
|
|
{"escape", 27},
|
|
|
|
|
{"space", ' '},
|
|
|
|
|
{"&", '&'},
|
|
|
|
|
{"and", '&'},
|
|
|
|
|
{"<", '<'},
|
|
|
|
|
{">", '>'},
|
|
|
|
|
{"f1", PU_KEY_F1},
|
|
|
|
|
{"f2", PU_KEY_F2},
|
|
|
|
|
{"f3", PU_KEY_F3},
|
|
|
|
|
{"f4", PU_KEY_F4},
|
|
|
|
|
{"f5", PU_KEY_F5},
|
|
|
|
|
{"f6", PU_KEY_F6},
|
|
|
|
|
{"f7", PU_KEY_F7},
|
|
|
|
|
{"f8", PU_KEY_F8},
|
|
|
|
|
{"f9", PU_KEY_F9},
|
|
|
|
|
{"f10", PU_KEY_F10},
|
|
|
|
|
{"f11", PU_KEY_F11},
|
|
|
|
|
{"f12", PU_KEY_F12},
|
|
|
|
|
{"left", PU_KEY_LEFT},
|
|
|
|
|
{"up", PU_KEY_UP},
|
|
|
|
|
{"right", PU_KEY_RIGHT},
|
|
|
|
|
{"down", PU_KEY_DOWN},
|
|
|
|
|
{"pageup", PU_KEY_PAGE_UP},
|
|
|
|
|
{"pagedn", PU_KEY_PAGE_DOWN},
|
|
|
|
|
{"home", PU_KEY_HOME},
|
|
|
|
|
{"end", PU_KEY_END},
|
|
|
|
|
{"insert", PU_KEY_INSERT},
|
|
|
|
|
{0, -1},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
FGDialog::getKeyCode(const char *str)
|
|
|
|
|
{
|
|
|
|
|
enum {
|
|
|
|
|
CTRL = 0x1,
|
|
|
|
|
SHIFT = 0x2,
|
|
|
|
|
ALT = 0x4,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
while (*str == ' ')
|
|
|
|
|
str++;
|
|
|
|
|
|
|
|
|
|
char *buf = new char[strlen(str) + 1];
|
|
|
|
|
strcpy(buf, str);
|
|
|
|
|
char *s = buf + strlen(buf);
|
|
|
|
|
while (s > str && s[-1] == ' ')
|
|
|
|
|
s--;
|
|
|
|
|
*s = 0;
|
|
|
|
|
s = buf;
|
|
|
|
|
|
|
|
|
|
int mod = 0;
|
|
|
|
|
while (1) {
|
|
|
|
|
if (!strncmp(s, "Ctrl-", 5) || !strncmp(s, "CTRL-", 5))
|
|
|
|
|
s += 5, mod |= CTRL;
|
|
|
|
|
else if (!strncmp(s, "Shift-", 6) || !strncmp(s, "SHIFT-", 6))
|
|
|
|
|
s += 6, mod |= SHIFT;
|
|
|
|
|
else if (!strncmp(s, "Alt-", 4) || !strncmp(s, "ALT-", 4))
|
|
|
|
|
s += 4, mod |= ALT;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int key = -1;
|
|
|
|
|
if (strlen(s) == 1 && isascii(*s)) {
|
|
|
|
|
key = *s;
|
|
|
|
|
if (mod & SHIFT)
|
|
|
|
|
key = toupper(key);
|
|
|
|
|
if (mod & CTRL)
|
2009-01-12 17:30:58 +00:00
|
|
|
|
key = toupper(key) - '@';
|
2009-06-27 08:09:10 +00:00
|
|
|
|
/* if (mod & ALT)
|
2005-11-05 18:41:43 +00:00
|
|
|
|
; // Alt not propagated to the gui
|
2009-06-27 08:09:10 +00:00
|
|
|
|
*/
|
2005-11-05 18:41:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
for (char *t = s; *t; t++)
|
|
|
|
|
*t = tolower(*t);
|
|
|
|
|
for (int i = 0; keymap[i].name; i++) {
|
|
|
|
|
if (!strcmp(s, keymap[i].name)) {
|
|
|
|
|
key = keymap[i].key;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete[] buf;
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGDialog::PropertyObject.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2009-01-12 17:30:58 +00:00
|
|
|
|
FGDialog::PropertyObject::PropertyObject(const char *n,
|
|
|
|
|
puObject *o, SGPropertyNode_ptr p) :
|
|
|
|
|
name(n),
|
|
|
|
|
object(o),
|
|
|
|
|
node(p)
|
2006-04-28 11:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2006-05-20 11:35:28 +00:00
|
|
|
|
// Implementation of fgValueList and derived pui widgets
|
2006-05-16 12:45:38 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fgValueList::fgValueList(SGPropertyNode *p) :
|
|
|
|
|
_props(p)
|
2003-01-20 16:01:16 +00:00
|
|
|
|
{
|
2006-05-16 12:45:38 +00:00
|
|
|
|
make_list();
|
2003-01-20 16:01:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-28 11:49:11 +00:00
|
|
|
|
void
|
2006-05-16 12:45:38 +00:00
|
|
|
|
fgValueList::update()
|
2006-04-28 11:49:11 +00:00
|
|
|
|
{
|
2006-05-16 12:45:38 +00:00
|
|
|
|
destroy_list();
|
|
|
|
|
make_list();
|
2006-04-28 11:49:11 +00:00
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
fgValueList::~fgValueList()
|
|
|
|
|
{
|
|
|
|
|
destroy_list();
|
|
|
|
|
}
|
2003-01-18 15:16:34 +00:00
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
void
|
|
|
|
|
fgValueList::make_list()
|
|
|
|
|
{
|
|
|
|
|
vector<SGPropertyNode_ptr> value_nodes = _props->getChildren("value");
|
|
|
|
|
_list = new char *[value_nodes.size() + 1];
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i = 0; i < value_nodes.size(); i++)
|
|
|
|
|
_list[i] = strdup((char *)value_nodes[i]->getStringValue());
|
|
|
|
|
_list[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fgValueList::destroy_list()
|
2003-01-18 15:16:34 +00:00
|
|
|
|
{
|
2006-05-16 12:45:38 +00:00
|
|
|
|
for (int i = 0; _list[i] != 0; i++)
|
|
|
|
|
if (_list[i])
|
|
|
|
|
free(_list[i]);
|
|
|
|
|
delete[] _list;
|
2003-01-18 15:16:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-05-16 12:45:38 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fgList::update()
|
|
|
|
|
{
|
|
|
|
|
fgValueList::update();
|
2008-03-11 15:58:57 +00:00
|
|
|
|
int top = getTopItem();
|
2006-05-16 12:45:38 +00:00
|
|
|
|
newList(_list);
|
2008-03-11 15:58:57 +00:00
|
|
|
|
setTopItem(top);
|
2006-05-16 12:45:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
// end of dialog.cxx
|