smlxlibmotifpolyml

PolyML/Motif: how do I simultaneously draw a window which contains an XmLabelPixmap button?


In PolyML, I am trying to draw a button with a pixmap in it, but cannot find a way to create the pixmap before calling XtRealizeWidget on the shell widget.

Using XCreateBitmapFromData after XtRealizeWidget, gives a huge delay in drawing the button with the picture in it, which is really silly. That is the code below.

the relevant lines are:

val   shell = XtAppInitialise "" "appl" "clss" [] [XmNwidth 500, XmNheight 500 ] ;
val   mainw = XmCreateMainWindow shell "window" [] ;
val   instruct = XmCreateDrawnButton mainw "button" [XmNwidth 60, XmNheight 30 , XmNlabelType XmPIXMAP,  XmNmappedWhenManaged true ];
val x =XtManageChildren [ instruct ] ;
val x=XtManageChild mainw ;

XtRealizeWidget shell;
let
 val thePic = XCreateBitmapFromData (XGetWindowRoot (XtWindow instruct)) (MakeData thePiclist)  (Area{x=0,y=0,w=25,h=25}) 
in
 XtSetValues instruct [XmNlabelPixmap thePic] 
end ;

I think that what I should do, to make the whole window - including the picture - to be shown simultaneously, is call XtSetValues before XtRealizeWidget, . I have't been able to make this work. The call of XGetWindowRoot, or any comparable call, does not work. Errors are like : X Error BadDrawable in XGetGeometry

Can anybody tell me how to create a window having a button with a pixmap in it , in such a way that everything is drawn simultaneously ?

remaining code:

open XWindows ;
open Motif ;

val thePiclist= [
   0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
   0x7c, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, 0xfc, 0x07, 0x00, 0x00,
   0xfc, 0x1f, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xfc, 0xff, 0x01, 0x00,
   0xfc, 0xff, 0x07, 0x00, 0xfc, 0xff, 0x1f, 0x00, 0xfc, 0xff, 0x7f, 0x00,
   0xfc, 0xff, 0xff, 0x00, 0xfc, 0xff, 0x7f, 0x00, 0xfc, 0xff, 0x1f, 0x00,
   0xfc, 0xff, 0x07, 0x00, 0xfc, 0xff, 0x01, 0x00, 0xfc, 0x7f, 0x00, 0x00,
   0xfc, 0x1f, 0x00, 0x00, 0xfc, 0x07, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00,
   0x7c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00];


fun MakeData []     = ""
 |   MakeData (H::T) = (str (chr H)) ^ (MakeData T) ;

Solution

  • Try

      Display *dpy = XtDisplay(shell);
      XCreateBitmapFromData( dpy, DefaultRootWindow(dpy), ... );