summaryrefslogtreecommitdiffstats
path: root/src/widgets/sp-attribute-widget.h
blob: f43fe84e70e459c9fef611a31da82e41f4b80d87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// SPDX-License-Identifier: GPL-2.0-or-later
/**
 * @file
 * Widget that listens and modifies repr attributes.
 */
/* Authors:
 *  Lauris Kaplinski <lauris@kaplinski.com>
 *  Kris De Gussem <Kris.DeGussem@gmail.com>
 *
 * Copyright (C) 2001 Ximian, Inc.
 * Copyright (C) 2002,2011-2012 authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef SEEN_DIALOGS_SP_ATTRIBUTE_WIDGET_H
#define SEEN_DIALOGS_SP_ATTRIBUTE_WIDGET_H

#include <gtkmm/widget.h>
#include <cstddef>
#include <sigc++/connection.h>

namespace Gtk {
class Entry;
class Grid;
}

namespace Inkscape {
namespace XML {
class Node;
}
}

class  SPObject;

/**
 * A base class for dialogs to enter the value of several properties.
 *
 * SPAttributeTable is used if you want to alter several properties of
 * an object. For each property, it creates an entry next to a label and
 * positiones these labels and entries one by one below each other.
 */
class SPAttributeTable : public Gtk::Widget {
public:
    /**
     * Constructor defaulting to no content.
     */
    SPAttributeTable ();
    
    /**
     * Constructor referring to a specific object.
     *
     * This constructor initializes all data fields and creates the necessary widgets.
     * set_object is called for this purpose.
     * 
     * @param object the SPObject to which this instance is referring to. It should be the object that is currently selected and whose properties are being shown by this SPAttributeTable instance.
     * @param labels list of labels to be shown for the different attributes.
     * @param attributes list of attributes whose value can be edited.
     * @param parent the parent object owning the SPAttributeTable instance.
     * 
     * @see set_object
     */
    SPAttributeTable (SPObject *object, std::vector<Glib::ustring> &labels, std::vector<Glib::ustring> &attributes, GtkWidget* parent);
    
    ~SPAttributeTable () override;
    
    /**
     * Sets class properties and creates child widgets
     *
     * set_object initializes all data fields, creates links to the
     * SPOject item and creates the necessary widgets. For n properties
     * n labels and n entries are created and shown in tabular format.
     * 
     * @param object the SPObject to which this instance is referring to. It should be the object that is currently selected and whose properties are being shown by this SPAttribuTable instance.
     * @param labels list of labels to be shown for the different attributes.
     * @param attributes list of attributes whose value can be edited.
     * @param parent the parent object owning the SPAttributeTable instance.
     */
    void set_object(SPObject *object, std::vector<Glib::ustring> &labels, std::vector<Glib::ustring> &attributes, GtkWidget* parent);
    
    /**
     * Update values in entry boxes on change of object.
     *
     * change_object updates the values of the entry boxes in case the user
     * of Inkscape selects an other object.
     * change_object is a subset of set_object and should only be called by
     * the parent class (holding the SPAttributeTable instance). This function
     * should only be called when the number of properties/entries nor
     * the labels do not change.
     * 
     * @param object the SPObject to which this instance is referring to. It should be the object that is currently selected and whose properties are being shown by this SPAttribuTable instance.
     */
    void change_object(SPObject *object);
    
    /**
     * Clears data of SPAttributeTable instance, destroys all child widgets and closes connections.
     */
    void clear();
    
    /**
     * Reads the object attributes.
     * 
     * Reads the object attributes and shows the new object attributes in the
     * entry boxes. Caution: function should only be used when which there is
     * no change in which objects are selected.
     */
    void reread_properties();
    
	/**
     * Gives access to the attributes list.
     */
    std::vector<Glib::ustring> get_attributes() {return _attributes;};
    
	/**
     * Gives access to the Gtk::Entry list.
     */
    std::vector<Gtk::Entry *> get_entries() {return _entries;};
    
	/**
     * Stores pointer to the selected object.
     */
    SPObject *_object;
    
	/**
     * Indicates whether SPAttributeTable is processing callbacks and whether it should accept any updating.
     */
    bool blocked;

private:
    /**
     * Container widget for the dynamically created child widgets (labels and entry boxes).
     */
    Gtk::Grid  *table;
    
    /**
     * List of attributes.
     * 
     * _attributes stores the attribute names of the selected object that
	 * are valid and can be modified through this widget.
     */
    std::vector<Glib::ustring> _attributes;
	/**
     * List of pointers to the respective entry boxes.
     * 
     * _entries stores pointers to the dynamically created entry boxes in which
	 * the user can midify the attributes of the selected object.
     */
    std::vector<Gtk::Entry *> _entries;
    
	/**
     * Sets the callback for a modification of the selection.
     */
    sigc::connection modified_connection;
    
	/**
     * Sets the callback for the deletion of the selected object.
     */
    sigc::connection release_connection;
};

#endif

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :