Graphic Attributes


ObjectEditor Widget

The graphic class, which is the base class for all graphic objects, defines the resources that control the appearance of an object, including line color, fill color, bitmap pattern, line width, etc. There is no built-in editor for those resources. Instead, widget class ObjectEditor is available for building a menu that can be used to create and/or edit graphic objects interactively. The appearance of the menu created by widget ObjectEditor can be entirely customized to fit your application's requirements. See Reference pages for a complete description of the resources and public functions defined by class ObjectEditor.

ObjectEditor Example

The following example (see file editor_1.c in directory examples) illustrates how to create an empty EditObject and a ObjectEditor panel that can be used to interactively create and edit objects in the EditObject window.

    #include <Xm/Form.h>
    #include <Xm/Frame.h>
    #include <Xint/EditObject.h>
    #include <Xint/ObjectEditor.h>
    #include <Xint/Text.h>
    #include <Xint/RoundedRect.h>
    #include <Xint/Rectangle.h>
    #include <Xint/Oval.h>
    #include <Xint/Line.h>
    #include <Xint/Polyline.h>
    #include <Xint/Polygon.h>
    #include <Xint/FreeHand.h>
    #include <Xint/Chart.h>

    /* Define list of pixmaps used when creating the ObjectEditor widget */
    static char *pixmap_names[] = { 
                    "50_percent_1", "50_percent_2", "Vertical1", "Horizontal1",
                    "Slant_Left1",  "Slant_Right1", "Weave2",    "Weave4",
                    "Diaper",       "Diamond2",     "Trellis1",  "Cross_Hatch",
                    "Tread2",       "Herring_Bone2","Zigzag2",   "Check2", 
                    NULL };

    main(argc, argv)
    int   argc;
    char  *argv[];
    {
        XtAppContext app_context;
        Widget       top_level;
        Widget       form, frame, edit, object_editor;
        ObjectClass  object_class_list[12];
        Pixmap       pixmap_list[20];
        int          n;

        top_level  = XtAppInitialize(&app_context, "object_editor",
                                     (XrmOptionDescList)NULL, 0,
                                     &argc, argv, NULL, NULL, 0);
        XtVaSetValues(top_level, XmNallowShellResize, True, NULL);

        /* Create a Form containter */
        form = XtVaCreateManagedWidget("form", xmFormWidgetClass,
                                       top_level, NULL);

        /* list the Object classes that we want to create interactively */
        n = 0;
        object_class_list[n] = xintRectangleObjectClass; n++;
        object_class_list[n] = xintRoundedRectObjectClass; n++;
        object_class_list[n] = xintOvalObjectClass; n++;
        object_class_list[n] = xintLineObjectClass; n++;
        object_class_list[n] = xintPolylineObjectClass; n++;
        object_class_list[n] = xintPolygonObjectClass; n++;
        object_class_list[n] = xintTextObjectClass; n++;
        object_class_list[n] = xintFreeHandObjectClass; n++;
        object_class_list[n] = xintChartObjectClass; n++;
        object_class_list[n] = NULL; n++;

        /* Build a list of bitmap patterns */
         n = 0;
         while (pixmap_names[n]) {
             pixmap_list[n] = 
                        XintObjectEditorGetDefinedPixmap(form, pixmap_names[n]);
             n++;
         }
         pixmap_list[n] = XmUNSPECIFIED_PIXMAP;
     
        /* Create an ObjectEditor widget */
        object_editor = XtVaCreateManagedWidget("object_editor",
                                         xintObjectEditorWidgetClass,
                                         form,
                                         XmNorientation, XintVERTICAL,
                                         XmNnumColumns, 1,
                                         XmNobjectOrientation, XmHORIZONTAL,
                                         XmNobjectNumColumns, 3,
                                         XmNpixmapNumColumns, 4,
                                         XmNpixmapList, pixmap_list,
                                         XmNshowAttributeLabels, False,
                                         XmNobjectClassList, object_class_list,
                                         /* Form constraint resources */
                                         XmNleftAttachment, XmATTACH_FORM,
                                         XmNtopAttachment, XmATTACH_FORM,
                                         XmNbottomAttachment, XmATTACH_FORM,
                                         NULL);

        /* Create an Frame widget */
        frame = XtVaCreateManagedWidget("frame", xmFrameWidgetClass,
                                        form,
                                        XmNshadowType,       XmSHADOW_IN,
                                        /* Form constraint resources */
                                        XmNrightAttachment,  XmATTACH_FORM,
                                        XmNtopAttachment,    XmATTACH_FORM,
                                        XmNbottomAttachment, XmATTACH_FORM,
                                        XmNleftAttachment,   XmATTACH_WIDGET,
                                        XmNleftWidget,       object_editor, 
                                        NULL);
     
        /* Create an EditObject widget */
        edit = XtVaCreateManagedWidget("edit_object", 
                                       xintEditObjectWidgetClass, frame,
                                       XmNwidth,            600,
                                       XmNheight,           600,
                                       XmNobjectEditMode,   XintEDIT_ADJUST, 
                                       NULL);

        /* Connect the object editor to the edit object widget */
        XintObjectEditorAddEditObjectToList(object_editor, edit);

        /* Loop */
        XtRealizeWidget(top_level);
        XtAppMainLoop(app_context);
    }

The output from this example is shown below:


Figure 18: ObjectEditor example output.


Editing Functions

Some applications may want to provide some of the functionality of the ObjectEditor widget by using their own interface. All of the controls available through the ObjectEditor widget class can be duplicated using public functions defined in the EditObject classes or by setting resources defined in the Graphic class. The following table indicates how to implement the functionality provided by the ObjectEditor widget class.

FunctionalityFunction or Resource
Inserting an object interactivelyXintEditObjectInsert.
Cut/Copy/pasteXintEditObjectCut, XintEditObjectCopy and XintEditObjectPaste.
Group/UngroupXintEditObjectGroup and XintEditObjectUngroup
Back/FrontXintEditObjectBack and XintEditObjectFront.
Lower/RaiseXintEditObjectLower and XintEditObjectRaise.
Set colorsSee resources XmNcolor, XmNfillColor and XmNstippleColor.
Set line styleSee resource XmNlineThickness and XmNlineStyle.
Set dash styleSee resource XmNdashList.
Set fill styleSee resource XmNfillStyle.
Set pixmap patternSee resource XmNfillPixmap.