| 1 | /* |
| 2 | * SPDX-FileName: property_list.hxx |
| 3 | * SPDX-FileComment: Implementation of the <property-list> widget. |
| 4 | * SPDX-FileCopyrightText: Copyright (C) 2001 Steve BAKER |
| 5 | * SPDX-FileCopyrightText: Copyright (C) 2001 Jim WILSON |
| 6 | * SPDX-FileCopyrightText: Copyright (C) 2006 Melchior FRANZ |
| 7 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 8 | */ |
| 9 | |
| 10 | #pragma once |
| 11 | |
| 12 | #include <string> |
| 13 | |
| 14 | // ensure we include this before puAux.h, so that |
| 15 | // #define _PU_H_ 1 has been done, and hence we don't |
| 16 | // include the un-modified system pu.h |
| 17 | #include "FlightGear_pu.h" |
| 18 | |
| 19 | #include <plib/puAux.h> |
| 20 | #include <simgear/props/props.hxx> |
| 21 | #include "FGPUIDialog.hxx" |
| 22 | |
| 23 | |
| 24 | class PropertyList : public puaList, public SGPropertyChangeListener, public GUI_ID { |
| 25 | public: |
| 26 | // If <readonly> is true, we don't show . or .. items and don't respond to |
| 27 | // mouse clicks or keypresses. |
| 28 | PropertyList(int minx, int miny, int maxx, int maxy, SGPropertyNode *root, bool readonly); |
| 29 | ~PropertyList(); |
| 30 | |
| 31 | void update (bool restore_slider_pos = false); |
| 32 | void setCurrent(SGPropertyNode *p); |
| 33 | SGPropertyNode *getCurrent() const { return _curr; } |
| 34 | void publish(SGPropertyNode *p) { _return = p; invokeCallback(); } |
| 35 | void toggleVerbosity() { _verbose = !_verbose; } |
| 36 | |
| 37 | // overridden plib pui methods |
| 38 | virtual char *getStringValue(void) |
| 39 | { |
| 40 | _return_path.clear(); |
| 41 | if (_return) |
| 42 | _return_path = _return->getPath(true); |
| 43 | return const_cast<char*>(_return_path.c_str()); |
| 44 | } |
| 45 | //virtual char *getListStringValue() { return (char *)(_return ? _return->getPath(true) : ""); } |
| 46 | virtual void setValue(const char *); |
| 47 | |
| 48 | // listener method |
| 49 | virtual void valueChanged(SGPropertyNode *node); |
| 50 | |
| 51 | private: |
| 52 | struct NodeData { |
| 53 | NodeData() : listener(0) {} |
| 54 | ~NodeData() { |
| 55 | if (listener) |
| 56 | node->removeChangeListener(listener); |
| 57 | } |
| 58 | void setListener(SGPropertyChangeListener *l) { |
| 59 | node->addChangeListener(listener = l); |
| 60 | } |
| 61 | SGPropertyNode_ptr node; |
| 62 | SGPropertyChangeListener *listener; |
| 63 | char **text; |
| 64 | }; |
| 65 | |
| 66 | // update the text string in the puList using the given node and |
| 67 | // updating the requested offset. |
| 68 | void updateTextForEntry(NodeData&); |
| 69 | void delete_arrays(); |
| 70 | static void handle_select(puObject *b); |
| 71 | static int nodeNameCompare(const void *, const void *); |
| 72 | |
| 73 | SGPropertyNode_ptr _curr; |
| 74 | SGPropertyNode_ptr _return; |
| 75 | |
| 76 | char **_entries; |
| 77 | int _num_entries; |
| 78 | |
| 79 | NodeData *_children; |
| 80 | int _num_children; |
| 81 | |
| 82 | bool _dot_files; // . and .. pseudo-dirs currently shown? |
| 83 | bool _verbose; // show SGPropertyNode flags |
| 84 | std::string _return_path; |
| 85 | bool _readonly; |
| 86 | }; |
| 87 | |
| 88 |