2001-11-12 20:57:08 +00:00
|
|
|
/*
|
|
|
|
prop_picker.hxx
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <plib/pu.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "gui.h"
|
2003-05-06 23:46:24 +00:00
|
|
|
#include <simgear/props/props.hxx>
|
2001-11-12 20:57:08 +00:00
|
|
|
|
|
|
|
void prop_pickerInit();
|
|
|
|
void prop_pickerView( puObject * );
|
|
|
|
void prop_pickerRefresh();
|
2003-02-04 22:27:58 +00:00
|
|
|
void prop_editInit( const char * name, const char * value );
|
|
|
|
void prop_editOpen( const char * name, const char * value );
|
2001-11-12 20:57:08 +00:00
|
|
|
|
|
|
|
class fgPropPicker ;
|
|
|
|
class fgPropEdit ;
|
|
|
|
|
2003-02-04 22:27:58 +00:00
|
|
|
class fgPropPicker :
|
|
|
|
public puDialogBox,
|
|
|
|
public SGPropertyChangeListener
|
2001-11-12 20:57:08 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
static void handle_select ( puObject *b ) ;
|
|
|
|
static void input_entered ( puObject *b ) ;
|
|
|
|
static void fgPropPickerHandleSlider ( puObject * slider );
|
|
|
|
static void fgPropPickerHandleArrow ( puObject *arrow );
|
|
|
|
static void fgPropPickerHandleOk ( puObject* b );
|
|
|
|
|
Patch from Julian Foad:
When the scroll bar slider is dragged, the list scrolls only far
enough to see all items; only the arrow buttons can scroll it so far
that the last item goes to the top of the view.
Fix scroll bar proportional size: was wrong when the list was only
a little longer than the visible area.
Minor fixes such as "delete files[i];" -> "delete[] files[i];"
(where the item being deleted is an array of characters) and removal of
global variables.
Smooth scrolling when dragging the slider: one item at a time,
rather than one tenth of the list at a time.
Fix a bug that would have occurred if instantiated with arrows=2.
Sort properties primarily by name and then by numerical index
order, rather than a simple ASCII string order. E.g. "js[1]", "js[2]",
"js[10]" rather than "js[1]", "js[10]", "js[2]".
Avoid crashing if the selected property path does not exist;
display an empty list instead. This cannot happen when the property
picker is working properly, but did happen due to missing indices prior
to this patch, and could happen if the user is allowed to type a
pathname, as in the http and telnet interfaces.
Fix truncation of strings to PUSTRING_MAX: was wrong when string
length was exactly 80.
Fix: move the scroll bar to the top each time a new list is
displayed. It was left at its previous position, while the top of the
new list was displayed, not corresponding to the slider.
Use getDisplayName instead of duplicated code: gives a better
decision on whether to display the index, and avoids invalid property
paths being generated which would previously crash find_props().
Replace unnecessary node lookups by name with direct access: tidier
and more efficient. E.g. "getValueTypeString
(node->getNode(name.c_str()))" -> "getValueTypeString (child)".
2002-09-07 12:35:06 +00:00
|
|
|
void delete_arrays () ;
|
|
|
|
|
2003-02-04 22:27:58 +00:00
|
|
|
/** 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);
|
|
|
|
|
2001-11-12 20:57:08 +00:00
|
|
|
char** files ;
|
|
|
|
int num_files ;
|
|
|
|
int arrow_count ;
|
|
|
|
char startDir [ PUSTRING_MAX * 2 ] ;
|
|
|
|
|
2003-02-04 22:27:58 +00:00
|
|
|
SGPropertyNode_ptr* children;
|
|
|
|
int num_children;
|
|
|
|
|
|
|
|
/** set if we're display the . and .. entries at the start of the
|
|
|
|
list */
|
|
|
|
bool dotFiles;
|
|
|
|
|
2001-11-12 20:57:08 +00:00
|
|
|
/* puInput *input ; */
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
puFrame *frame ;
|
|
|
|
puListBox *list_box ;
|
|
|
|
puSlider *slider ;
|
|
|
|
puOneShot *cancel_button ;
|
|
|
|
puOneShot *ok_button ;
|
2002-02-05 22:32:29 +00:00
|
|
|
puArrowButton *down_arrow ;
|
|
|
|
puArrowButton *up_arrow ;
|
2001-11-12 20:57:08 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
puText *proppath ;
|
|
|
|
void find_props () ;
|
|
|
|
fgPropPicker ( int x, int y, int w, int h, int arrows,
|
|
|
|
const char *dir, const char *title = "Pick a file" ) ;
|
|
|
|
|
|
|
|
~fgPropPicker () {;}
|
|
|
|
|
|
|
|
static void go_up_one_directory ( char *fname ) ;
|
|
|
|
static void chop_file ( char *fname ) ;
|
|
|
|
|
2003-02-04 22:27:58 +00:00
|
|
|
// over-ride the method from SGPropertyNodeListener
|
|
|
|
virtual void valueChanged (SGPropertyNode * node);
|
2001-11-12 20:57:08 +00:00
|
|
|
} ;
|
|
|
|
|
|
|
|
class fgPropEdit : public puDialogBox
|
|
|
|
{
|
|
|
|
|
|
|
|
static void fgPropEditHandleCancel ( puObject *b ) ;
|
|
|
|
static void fgPropEditHandleOK ( puObject* b );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
puFrame *frame ;
|
|
|
|
puOneShot *cancel_button ;
|
|
|
|
puOneShot *ok_button ;
|
|
|
|
|
|
|
|
public:
|
|
|
|
puText *propname ;
|
|
|
|
puInput *propinput ;
|
|
|
|
char propPath [ PUSTRING_MAX * 2 ] ;
|
|
|
|
|
2003-02-04 22:27:58 +00:00
|
|
|
fgPropEdit ( const char *name, const char *value, char *proppath ) ;
|
2001-11-12 20:57:08 +00:00
|
|
|
|
|
|
|
~fgPropEdit () {;}
|
|
|
|
|
|
|
|
static void go_up_one_directory ( char *fname ) ;
|
|
|
|
static void chop_file ( char *fname ) ;
|
|
|
|
|
|
|
|
} ;
|