Object Editing


Introduction

The ChartObject library offers a lot of flexibility when it comes to selecting, editing or modifying object resources interactively. The following section covers some of the main issues regarding object editing.

Object Selection

Any graphic object displayed in an EditObject widget can be selected. Selected objects are highlighted using handle bars or by drawing the outline of the object using a specified color. Graphic resource XmNhighlightMode can be used to set how each object should be highlighted. By default, each object created is selectable. To prevent the end-user from selecting an object, set Graphic resource XmNsensitive to False when you create the object.

A Chart object does not normally propagate resource changes to its sub-objects. To make a Chart object and all of its components non selectable, set resource XmNpropagate to True each time you want the change to be applied to all the chart components, as shown in the code sample below:

    XtVaSetValues ((Widget) chart, XmNsensitive, False, 
                   XmNpropagate, True, NULL);

The EditObject actions that control object selection are ObjectSelect, InitAreaSelection, ExtendAreaSelection and EndAreaSelection. These actions are connected as follows in the default EditObject translation table:

ActionDefault Selection Translation
Ctrl<Btn1Down>InitAreaSelection(extend) ObjectSelect(single)
None<Btn1Down>InitAreaSelection(single) ObjectSelect(single)
<PtrMoved>ObjectSelect()
<Btn1Up>ObjectEditEnd()

This table shows that Button1 is used to select an object. If you press the Ctrl key while doing the selection, the object is added to the list of selected objects. Otherwise, the current selection list is erased before the object is selected. Also, if you drag Button1 while pressing it, all the objects contained in the rectangular area outlined while the cursor is moved will be selected when the button is released.

EditObject callbacks XmNobjectSelectionCallback and XmNobjectDeselectionCallback can be used by the application to determine when an object has been selected or deselected. For objects in a group, the Group object ID is returned as the selected object. Since a Chart is a group of objects, the ChartObject ID will be returned when a chart sub-component is selected. Use function XintChartGetSelectedComponent to find out the type and object ID of the sub-component that was selected. The following code segment shows how to write a selection callback that prints the name of the selected object.

    static void ObjectSelectionCallback (Widget, data, cb)
    Widget widget;
    XtPointer data;
    XintEditObjectSelectionCallbackStruct *cb;
    {
       Object selected_object;
       int code;
    
       if (XintIsChart(cb->object))
           selected_object = XintChartGetSelectedComponent(cb->object, &code);
       else
           selected_object = cb->object;

       printf("Selected object name = %s\n", XtName((Widget) cb->object));
    }


Moving and Resizing Objects

Object moving and resizing is controlled by EditObject actions ObjectEditStart, ObjectEdit and ObjectEditEnd. These actions are connected to Button1 in the default translation table for the EditObject class as shown in the table below:

ActionDefault Editing Translation
None <Btn1Down>ObjectEditStart()
<PtrMoved>ObjectEdit()
<Btn1Up>ObjectEditEnd()

Action ObjectEditStart supports an argument. For example, if you just want the end-user to move objects, you can specify ObjectEditStart(move) in the translation table. If you don't specify an argument to action ObjectEditStart, the behavior of this action is controlled by EditObject resource XmNobjectEditMode. The purpose of this resource is to enable you to modify the behavior of action ObjectEditStart without having to redefine a new translation table. By default, resource XmNobjectEditMode is set to XintEDIT_NONE which disables all editing. To enable full object editing, set this resource to constant XintEDIT_ADJUST. See editobject.c in the demos directory, EditObject subdirectory.

Object editing can also be controlled on an object by object basis using resources XmNmove and XmNshape. These resources are set to True by default. To disable editing for a particular object, set XmNmove and/or XmNshape to False.


Verify Callback

Callback XmNverifyCallback is a callback that can be registered on any graphic object. It is invoked whenever the object has been edited. For example, this callback will be invoked each time an object has been moved or resized. Most classes redefine the callback structure that is returned with this callback to provide specific information relevant to each object class.

For chart objects, in addition to being called for the reasons described above, this callback is also invoked when the chart type has been changed. The callback structure returns both the old and the new chart type.