Re: Custom Extensions to new Shapes



At 17.09.2012 14:25, Dave Johnston wrote:
It would be great if the XML used to create shapes could be extended to
support a few other types.
I think most cases could be catered for if the following was available
(maybe it already is and I haven't seen it)

Tne suggested functionality would certainly but useful, I'm pondering the idea to make more use of the Dia "StdProps" type system from custom shapes for a while, but am not aware of any code written to actually do that.

Enums and Composite Types - i.e. something along the lines of

Enum:
<ext_attribute name="DayOfWeek" type="enum">
<value type="string">MON</value>
<value type="string">TUE</value>
<value type="string>WED</value>
</ext_attribute>

This would be represented as a drop down box on the attributes page.

Having names and values independent would give a better fit to what's already there. See lib/prop_inttypes.[hc] - EnumProperty for the basics. Grep PROP_TYPE_ENUM for actual uses. You would not have to write any new user interface just provide the right PropDescription.

Composite Type:
<ext_attribute name="Date" type="composite">
<attribute name="Day" type="int"/>
<attribute name="Month" type="string"/>
<attribute name="Year" type="int"/>
</ext_attribute>

This would be represented on a single line like this (obviously with
current values subsidised):

______________________________
|Day: 17 | Month: Sept | Year: 2012 |
|_______|___________|__________|

For this I'd suggest to add a new type 'date', which would use GtkCalendar for it's widget. Should maybe use GDateTime for the backend - although that would require to bump the minumium GLib version.

The general composite case migh still be useful, but doing a good and compatible automatic user interface for it might be hard. The default representation in property dialogs is
        Description : Widgets
see the recently added MatrixProperty for a bad example having more than one widget ;-)

Are there any plans do add this kind of functionality? If not could anyone
suggest what files I would need to start looking at to add support for the
enum type at least ? I've been looking at custom_object.c, but still trying
to figure out how all the attributes are parsed and the resultant data is
drawn to screen.

custom/shape_info.c should do the translation from XML to PropDescription (it currently does so by calling custom_setup_properties()). For the enum type and other PropDescription::extra_data has to be filled. For enum it is a vector of PropEnumData, see e.g. prop_std_text_align_data in properties.h. For other types it would also be useful to fill these to eg. define upper and lower limit.

custom/custom_object.c should just contain code to merge PropDesciptions in custom_describe_props(); maybe also modify custom_get_props() and custom_set_props() to split the given properties between existing struct _Custom fields and extended properties.

There is a flaw in the current implementation of custom_setup_properties() but I would to think more about it to suggest a fix.

HTH,
        Hans

-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to
get along without it.                -- Dilbert



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]