Newsgroups: comp.windows.x.motif
Date: Tue,  8 Sep 1992 22:59:58 -0400 
From: "Joseph C. Lappa" <jl8p+@andrew.cmu.edu>
Subject: Help with Widgets


Hello,


   I've recently begun to program in Motif.  I'm currently writing a
small and simple drawing program.  What I would like to do is use the
example from OReilly's X Book on Moif (#6) example of a color slide to
select colors.  I have to the point where I would like it to be, but the
dialog widget that comes up is "squished".  I don't know how else to
describe it.  Any help in correcting this would be APPRECIATED!!  I have
been toying with it for 3 days not and haven't gotten anywhere.

Thanks!
Joe Lappa


Here is the modified subroutine:

/* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
 * This program is freely distributable without licensing fees and
 * is provided without guarantee or warrantee expressed or implied.
 * This program is -not- in the public domain.
 */

/* color_slide.c -- Use scale widgets to display the different
 * colors of a colormap.
 */

#include <Xm/Xm.h>
#include <Xm/MainW.h>
#include <Xm/Scale.h>
#include <Xm/RowColumn.h>
#include <Xm/RowColumnP.h>
#include <Xm/DrawingA.h>
#include <Xm/DialogS.h>
#include <Xm/PushBG.h>

extern Widget toplevel;
void new_value();

Widget colorwindow; /* the window the siplays a solid color */
XColor color;       /* the color in the colorwindow */


void RGB_Input()
{
    Widget        dialogshell,dialog,rowcol, scale, rowcol2,button1,button2;
    Widget 	  separator,rowcol1;
    Pixel         background;
    XtVarArgsList arglist;
    Arg		  args[20];
    int           n = 0;

    if (DefaultDepthOfScreen(XtScreen(toplevel)) < 2) {
        puts("You must be using a color screen.");
        exit(1);
    }

    color.flags = DoRed|DoGreen|DoBlue;

    /* initialize first color */

    XAllocColor(XtDisplay(toplevel),
        DefaultColormapOfScreen(XtScreen(toplevel)), &color);

    n = 0;
    XtSetArg(args[n], XmNtitle, "Edit Colors");n++;
    XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL);n++;
    XtSetArg(args[n], XmNdeleteResponse, XmDESTROY);n++;
    XtSetArg(args[n], XmNautoUnmanage, False); n++;

/*
    XtSetArg(args[n], XmNwidth ,  234);n++;
    XtSetArg(args[n], XmNheight, 421);n++; 
*/
    XtSetArg(args[n],XmNnoResize, False);n++;

    dialogshell = XmCreateDialogShell(toplevel,"dialogshell",args,n);

    arglist = XtVaCreateArgsList(NULL,
        XmNwidth ,  234,
        XmNheight,  421,
        NULL);

    rowcol = XtVaCreateManagedWidget("rowcol",
        xmRowColumnWidgetClass, dialogshell, 
        XtVaNestedList, arglist, 
        NULL);

    colorwindow = XtVaCreateManagedWidget("colorwindow",
        widgetClass,   rowcol, 
        XmNheight,     100,
        XmNwidth,      250,
        XmNbackground, color.pixel,
        NULL);

    /* use rowcol again to create another RowColumn under the 1st */

    rowcol = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, rowcol,
        XmNorientation, XmHORIZONTAL,
        NULL);

    arglist = XtVaCreateArgsList(NULL,
        XmNshowValue, True,
        XmNmaximum, 255,
        XmNscaleMultiple, 5,
        NULL);

    scale = XtVaCreateWidget("Red",
        xmScaleWidgetClass, rowcol,
        XtVaNestedList, arglist,
        XtVaTypedArg, XmNtitleString, XmRString, "Red", 4,
        XtVaTypedArg, XmNforeground, XmRString, "Red", 4,
        NULL);
    XtAddCallback(scale, XmNdragCallback, new_value, DoRed);
    XtAddCallback(scale, XmNvalueChangedCallback, new_value, DoRed);

    XtManageChild(scale);

    scale = XtVaCreateWidget("Green",
        xmScaleWidgetClass, rowcol,
        XtVaNestedList, arglist,
        XtVaTypedArg, XmNtitleString, XmRString, "Green", 6,
        XtVaTypedArg, XmNforeground, XmRString, "Green", 6,
        NULL);
    XtAddCallback(scale, XmNdragCallback, new_value, DoGreen);
    XtAddCallback(scale, XmNvalueChangedCallback, new_value, DoGreen);

    XtManageChild(scale);

    scale = XtVaCreateWidget("Blue",
        xmScaleWidgetClass, rowcol,
        XtVaNestedList, arglist,
        XtVaTypedArg, XmNtitleString, XmRString, "Blue", 5,
        XtVaTypedArg, XmNforeground, XmRString, "Blue", 5,
        NULL);
    XtAddCallback(scale, XmNdragCallback, new_value, DoBlue);
    XtAddCallback(scale, XmNvalueChangedCallback, new_value, DoBlue);


    XtManageChild(scale);

    arglist = XtVaCreateArgsList(NULL,
        XmNwidth ,  200,
        XmNheight,  200,
        XmNorientation, XmHORIZONTAL,
        XmNx,           0,
        XmNy,         250,
        NULL);

   rowcol2 = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, rowcol,
             XtVaNestedList, arglist,
             NULL);

    arglist = XtVaCreateArgsList(NULL,
        XmNwidth,   60,
        XmNheight,  30, 
        XmNlabelString, XmStringCreate("  Ok", XmSTRING_DEFAULT_CHARSET),
        XmNrecomputeSize, False,
        XmNshadowType,    XmSHADOW_ETCHED_IN,
        NULL);

    button1 = XtVaCreateWidget("Ok",
               xmPushButtonGadgetClass,rowcol2, 
               XtVaNestedList, arglist,
	       NULL);

    XtManageChild(button1);

    arglist = XtVaCreateArgsList(NULL,
        XmNwidth,   60,
        XmNheight,  30,
        XmNlabelString, XmStringCreate("Cancel", XmSTRING_DEFAULT_CHARSET),
        XmNrecomputeSize, False,
        XmNshadowType,    XmSHADOW_ETCHED_OUT,
        NULL);

    button2 = XtVaCreateWidget("Cancel",
              xmPushButtonGadgetClass,rowcol2,
              XtVaNestedList, arglist,
              NULL);

    XtManageChild(button2);
   
    XtFree(arglist);
    XtManageChild(rowcol);
    XtManageChild(rowcol2);
    XtManageChild(dialogshell); 
    XtPopup(dialogshell,XtGrabNone);
}

void
new_value(scale_w, rgb, cbs)
Widget scale_w;
int rgb;
XmScaleCallbackStruct *cbs;
{
    Colormap cmap = DefaultColormapOfScreen(XtScreen(scale_w));

    switch (rgb) {
        case DoRed :
            color.red = (cbs->value << 8);
            break;
        case DoGreen :
            color.green = (cbs->value << 8);
            break;
        case DoBlue :
            color.blue = (cbs->value << 8);
    }

    /* reuse the same color again and again */
    XFreeColors(XtDisplay(scale_w), cmap, &color.pixel, 1, 0);
    if (!XAllocColor(XtDisplay(scale_w), cmap, &color))
        puts("Couldn't XallocColor!"), exit(1);
    XtVaSetValues(colorwindow, XmNbackground, color.pixel, NULL);
}

Newsgroups: comp.windows.x.motif