GOStyledObject: GOffice Reference Manual

## GOStyledObject GOStyledObject — Objects with style |

## Functions

void | go_styled_object_apply_theme ()
void | go_styled_object_fill ()
GOStyle * | go_styled_object_get_auto_style ()
GODoc * | go_styled_object_get_document ()
GOStyle * | go_styled_object_get_style ()
gboolean | go_styled_object_set_cairo_line ()
gboolean | go_styled_object_set_style ()
void | go_styled_object_style_changed ()

## Types and Values

| GOStyledObject
| GOStyledObjectClass

## Object Hierarchy

        GInterface
        ╰── GOStyledObject

## Known Implementations

GOStyledObject is implemented by GocArc, GocCircle, GocEllipse, GocLine, GocPath, GocPolygon, GocPolyline, GocRectangle, GocStyledItem, GocText, GogAxis, GogAxisBase, GogAxisLine, GogChart, GogColorScale, GogDataLabel, GogGraph, GogGrid, GogGridLine, GogLabel, GogLegend, GogOutlinedObject, GogRegCurve, GogRegEqn, GogSeries, GogSeriesElement, GogSeriesLabels, GogSeriesLines, GogSmoothedCurve, GogStyledObject, GogText and GogTrendLine.

## Description

The common GInterface for all objects owning a GOStyle.

## Functions

### go_styled_object_apply_theme ()

    void
    go_styled_object_apply_theme (GOStyledObject *gso,
                                  GOStyle *style);

Apply appropriate theme `style` if meaningful, i.e. properties with auto flag set to `TRUE` should be changed to default theme value.

#### Parameters

gso | a GOStyledObject |
style | a GOStyle that will be themed |

### go_styled_object_fill ()

    void
    go_styled_object_fill (GOStyledObject const *so,
                           cairo_t *cr,
                           gboolean preserve);

fills the current path according to the item style and canvas scale.

#### Parameters

so | GOStyledObject |
cr | cairo_t |
preserve | whether the current path should be preserved |

### go_styled_object_get_auto_style ()

    GOStyle *
    go_styled_object_get_auto_style (GOStyledObject *gso);

This function returns a new style that is initialized with the auto values for `gso` . Caller is responsible for the result.

#### Parameters

gso | a GOStyledObject |

#### Returns

a new GOStyle.

[transfer full][nullable]

### go_styled_object_get_document ()

    GODoc *
    go_styled_object_get_document (GOStyledObject *gso);

A GODoc is necessary to store images. If no GODoc is associated with the object, image filling will not be supported.

#### Parameters

gso | a GOStyledObject |

#### Returns

the GODoc associated with the object if any.

[transfer none][nullable]

### go_styled_object_get_style ()

    GOStyle *
    go_styled_object_get_style (GOStyledObject *gso);

Simply an accessor function that returns `gso->style` , without referencing it.

#### Parameters

gso | a GOStyledObject |

#### Returns

the styled object's GOStyle.

[transfer none][nullable]

### go_styled_object_set_cairo_line ()

    gboolean
    go_styled_object_set_cairo_line (GOStyledObject const *so,
                                     cairo_t *cr);

Prepares the cairo context `cr` to draw a line according to the item style and canvas scale.

#### Parameters

so | GOStyledObject |
cr | cairo_t |

#### Returns

`TRUE` if the line is not invisible

### go_styled_object_set_style ()

    gboolean
    go_styled_object_set_style (GOStyledObject *gso,
                                GOStyle *style);

Sets a new style for `gso` , and emits "style-changed" signal. This function does not take ownership of `style` .

The best way to change the style is to set the "style" property.

This function will fail if the new style and the previous style are the same. In that case, the function will always return false:

    1
    2
    3
    style = go_styled_object_get_style (gso);
    style->line.width = 2;
    size_changed = go_styled_object_set_style (gso, style);

In this sample, the call to `go_styled_object_set_style()` is just useless. You need to check yourself if you really change the size, call `go_styled_object_style_changed()` to trigger the "style-changed" event. So the following code is much better:

    1
    2
    3
    4
    5
    6
    7
    style = go_styled_object_get_style (gso);
    if (style->line.width != 2.) {
     style->line.width = 2;
     go_styled_object_style_changed (gso);
     size_changed = true;
    } else
     size_changed = FALSE;

or even better:

    1
    2
    3
    4
    style = go_style_dup (go_styled_object_get_style (gso));
    style->line.width = 2;
    size_changed = go_styled_object_set_style (gso, style);
    g_object_unref (style);

#### Parameters

gso | a GOStyledObject |
style | a GOStyle |

#### Returns

`TRUE` if new style may lead to change of object size, which happens when changing font size for example.

### go_styled_object_style_changed ()

    void
    go_styled_object_style_changed (GOStyledObject *gso);

Called when the style changed. Might emit a signal if meaningful.

#### Parameters

gso | a GOStyledObject |

## Types and Values

### GOStyledObject

    typedef struct _GOStyledObject GOStyledObject;

### GOStyledObjectClass

    typedef struct {
    	GTypeInterface		   base;

    	gboolean  (*set_style) 	    (GOStyledObject *gso, GOStyle *style);
    	GOStyle	 *(*get_style)	    (GOStyledObject *gso);
    	GOStyle	 *(*get_auto_style) (GOStyledObject *gso);
    	void	  (*style_changed)  (GOStyledObject *gso);
    	void	  (*apply_theme) (GOStyledObject *gso, GOStyle *style);
    	GODoc    *(*get_document)   (GOStyledObject *gso);
    } GOStyledObjectClass;

#### Members

GTypeInterface `base`; | base class |
`set_style` () | sets the object style. |
`get_style` () | returns the object current style. |
`get_auto_style` () | returns the default style for the object. |
`style_changed` () | called when the style changed. |
`apply_theme` () | apply the current theme if any to the object style. |
`get_document` () | returns the GODoc associated to the object if any. |