~ubuntu-branches/ubuntu/quantal/libbonobo/quantal-201207170711

« back to all changes in this revision

Viewing changes to doc/api/properties.xml

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-02-18 14:40:51 UTC
  • mto: (3.1.1 etch) (1.1.25 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050218144051-fo4h9qh2gim8x3wt
Tags: upstream-2.8.1
ImportĀ upstreamĀ versionĀ 2.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<refentry id="properties">
 
2
    <refmeta>
 
3
        <refentrytitle>Properties</refentrytitle>
 
4
<!--    <manvolnum>3</manvolnum> -->
 
5
        <refmiscinfo>LIBBONOBO Library</refmiscinfo>
 
6
        <refname>bonobo-arg</refname><refpurpose>simplified CORBA_Any wrappers</refpurpose>
 
7
 
 
8
    </refmeta>
 
9
 
 
10
    <refsect1>
 
11
        <title>Properties</title>
 
12
        
 
13
        <para>Bonobo component properties, version 0.1 by Michael
 
14
            Meeks &lt;mmeeks@gnu.org&gt;</para>
 
15
        
 
16
        <para>A brief discussion of how to use the property API to add
 
17
            a simple to use configuration mechanism to your bonobo
 
18
            component.</para>
 
19
 
 
20
        <refsect2><title>Properties and bags</title>
 
21
            
 
22
            <para>A property is an attribute that is attached to a
 
23
                Bonobo object.  It can have any type, although the
 
24
                standard types <type>boolean</type>,
 
25
                <type>long</type>, <type>float</type>, double, string
 
26
                are handled in a convenient fashion. Properties are
 
27
                attached to a <classname>PropertyBag</classname>
 
28
                object that is attached to your control or component
 
29
                in some way.</para>
 
30
        </refsect2>
 
31
            
 
32
        <refsect2><title>BonoboArgs</title>
 
33
 
 
34
            <para>A bonobo arg contains the value of a property whilst
 
35
                it is 'in flight' between a property and a
 
36
                requestor. The bonobo arg system is designed to make
 
37
                ORBit's 'any' code easier to use and less error prone
 
38
                - it is however simply a wrapper around a
 
39
                <type>CORBA_any</type>.</para>
 
40
 
 
41
            <para>A number of macros and helper functions are provided
 
42
                in <filename>bonobo-arg.h</filename>. Particularly,
 
43
                the type macros of BonoboArgType eg.</para>
 
44
            <para><literal>BONOBO_ARG_BOOLEAN, BONOBO_ARG_LONG,
 
45
                BONOBO_ARG_STRING</literal></para>
 
46
 
 
47
            <para>And a number of access procedures for getting and
 
48
                setting standard values from a BonoboArg. Eg. if 'a'
 
49
                is a <type>BonoboArg *</type> we should use:</para>
 
50
            <para><literal>BONOBO_ARG_GET_STRING (a)</literal> to get its string value</para>
 
51
            <para> or </para>
 
52
            <para><literal>BONOBO_ARG_SET_STRING (a, "GNU")</literal>to set its string value</para>
 
53
 
 
54
            <!-- Note: original docs said that passing NULL would -->
 
55
            <!-- cause crashes, but that's no longer true; I checked. -->
 
56
            <para>NB. Passing a NULL string to
 
57
            <function>BONOBO_ARG_SET_STRING</function> is equivalent
 
58
            to passing an empty string.</para>
 
59
 
 
60
            <para> The bonobo-arg code also provides functions for
 
61
                mapping <type>GParamSpec</type>s to BonoboArgs and
 
62
                vice-versa.</para>
 
63
 
 
64
        </refsect2>
 
65
 
 
66
        <refsect2><title>PropertyBag creation</title>
 
67
 
 
68
            <para>To add properties to an object first we must create
 
69
                a property bag hence:</para>
 
70
            <synopsis>
 
71
BonoboPropertyBag *bonobo_property_bag_new (BonoboPropertyGetFn get_prop,
 
72
                                            BonoboPropertySetFn set_prop,
 
73
                                            gpointer            user_data);
 
74
            </synopsis>
 
75
            
 
76
            <para> Each property has a get / set / user_data (GSU)
 
77
                triplet that handles that property's behavior. In a
 
78
                typical scenario all object properties in a bag
 
79
                utilise the same GSU triplet, and are identified
 
80
                inside the get / set functions by a unique enumerated
 
81
                constant arg_id.  Inside the function this arg_id can
 
82
                then be used with a switch statement to provide
 
83
                efficient (de)multiplexing of property
 
84
                requests. </para>
 
85
            
 
86
            <para> For particularly obtuse persons wanting more
 
87
                flexibility it is possible to specify the GSU triplet
 
88
                per property using the add_full variant. </para>
 
89
 
 
90
        </refsect2>
 
91
 
 
92
        <refsect2><title>Property Creation</title>
 
93
 
 
94
            <para> Each basic property is created by this function: </para>
 
95
            <synopsis>
 
96
void bonobo_property_bag_add (BonoboPropertyBag   *pb,
 
97
                              const char          *name,
 
98
                              int                  idx,
 
99
                              BonoboArgType        type,
 
100
                              BonoboArg           *default_value,
 
101
                              const char          *docstring,
 
102
                              BonoboPropertyFlags  flags);
 
103
            </synopsis>
 
104
            
 
105
            <para> It looks horrendous, but is horribly simple in most
 
106
                cases; the idx is the index that will be passed to a
 
107
                generic get / set function for this property. The type
 
108
                is one of the BonoboArgType macros discussed in
 
109
                section 2 which maps to an ORBit TypeCode [ hence any
 
110
                arbitary type can be added without the property-bag
 
111
                knowing anything about it ( allocation of that type is
 
112
                the users responsibility ) ]. Default_value is either
 
113
                NULL or a value created thusly:</para>
 
114
            <programlisting>
 
115
BonoboArg *def = bonobo_arg_new (BONOBO_ARG_DOUBLE);
 
116
BONOBO_ARG_SET_DOUBLE (def, 0.3127);
 
117
            </programlisting>
 
118
 
 
119
            <para>It's reference is stored in the property_bag.</para>
 
120
 
 
121
            <para> The rest of the code is internal and extremely
 
122
                transparent. In order to implement the get / set
 
123
                functions I would copy &amp; paste the sample code in:
 
124
                <filename>libbonoboui/samples/controls/bonobo-sample-controls.c.
 
125
                </filename></para>
 
126
        </refsect2>
 
127
        <refsect2><title>Wrapping GObjects</title>
 
128
 
 
129
            <para> If you have already implemented a GObject that
 
130
                has the set of properties that you wish to export as
 
131
                Bonobo properties then it is trivial to add them to
 
132
                the property bag using a transparent mapping. This
 
133
                means that you do not have to write any more code,
 
134
                simply use:</para>
 
135
            <programlisting>
 
136
GParamSpec **pspecs;
 
137
guint        n_props;
 
138
 
 
139
pspecs = g_object_class_list_properties (
 
140
      G_OBJECT_GET_CLASS (my_object), &amp;n_props);
 
141
 
 
142
bonobo_property_bag_map_params (pb, my_object, pspecs, n_props);
 
143
 
 
144
g_free (pspecs)
 
145
            </programlisting>
 
146
        </refsect2>
 
147
 
 
148
        <refsect2><title>Using properties in your client application</title>
 
149
 
 
150
            <para>There are some fairly typesafe but convenient vararg
 
151
                ways to get remote properties. Example:</para>
 
152
            <informalexample><programlisting>
 
153
CORBA_double i;
 
154
 
 
155
bonobo_widget_get_property (control, "value",
 
156
                            TC_CORBA_double, &amp;i, NULL);
 
157
i+= 0.37;
 
158
bonobo_widget_set_property (control, "value",
 
159
                            TC_CORBA_double, i, NULL);
 
160
                </programlisting></informalexample>
 
161
 
 
162
            <para>The alternative being the even more type safe version:</para>
 
163
            <programlisting>
 
164
bonobo_property_bag_client_get_value_gdouble (pb, "value", &amp;i);
 
165
            </programlisting>
 
166
 
 
167
        </refsect2>
 
168
 
 
169
    </refsect1>
 
170
</refentry>
 
171
 
 
172
 
 
173
 
 
174
 
 
175