home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / windows / x / motif / 5655 < prev    next >
Encoding:
Text File  |  1992-08-17  |  4.3 KB  |  126 lines

  1. Newsgroups: comp.windows.x.motif
  2. Path: sparky!uunet!ods!chris
  3. From: chris@ods.com (Chris Atkins)
  4. Subject: Re: Popup dialog and GC problem
  5. Message-ID: <1992Aug17.190200.2595@ods.com>
  6. Organization: Optical Data Systems, Inc.
  7. X-Newsreader: Tin 1.1 PL5
  8. References: <19834@leadsv.UUCP>
  9. Date: Mon, 17 Aug 1992 19:02:00 GMT
  10. Lines: 114
  11.  
  12. Lincoln McFarland (mcfar@leadse5.UUCP) wrote:
  13. : I have been creating pop up dialogs along the model suggested by Young p. 114
  14. : and can get things to work reasonably well with a few exceptions.  Basicly
  15. : I code the following:
  16. : main()
  17. : {
  18. :    Widget toplevel;
  19. :    Widget form;
  20. :    Widget button;
  21. :    Widget dialog;
  22. :    toplevel = XtInitialize( argv[0], "fred", NULL, 0, &argc, argv);
  23. :    form =  XtCreateManagedWidget( "form", xmFormWidgetClass, toplevel, al, ac);
  24. :    button = XtCreateManageddWidget( "button", xmPushButtonWidgetClass, 
  25. :                                     form, al, ac);
  26. :    dialog = create_dialog( toplevel );
  27. :    XtAddCallback( button, XmNactivateCallback, show_dialog, dialog);
  28. :    XtRealizeWidget( toplevel );
  29. :    XtMainLoop();
  30. : } /* end main */
  31. : Show dialog is just XtManageChild(dialog) like Young p. 115
  32. : Create dialog is along the lines of:
  33. : Widget create_dialog( parent )
  34. : Widget parent;
  35. : {
  36. :    Widget local_dialog;
  37. :    /* logo resources */
  38. :    XGCValues   arrow_val;
  39. :    pixmap_data arrow_pd;
  40. :    Widget      arrow;
  41. :    local_dialog = XmCreateFormDialog( parent, "dialog", al, ac);
  42. :    /*-- create a arrow image  --*/
  43. :    ac = 0;
  44. :    arrow = XtCreateManagedWidget( "arrow",
  45. :                                xmDrawingAreaWidgetClass, local_dialog, al,ac);
  46. :    /* Use the forground and background colors of the logo to
  47. :       create a graphics context */
  48. :    ac = 0;
  49. :    XtSetArg (al[ac], XtNforeground, &downHead_val.foreground); ac++;
  50. :    XtSetArg (al[ac], XtNbackground, &downHead_val.background); ac++;
  51. :    XtGetValues (downHead, al, ac);
  52. :    arrow_pd.gc = XtGetGC (arrow, GCForeground|GCBackground,
  53. :                             &arrow_val);
  54. :    arrow_pd.width  = arrow_width;
  55. :    arrow_pd.height = arrow_height;
  56. :    arrow_pd.pix = create_pixmap(arrow, arrow_pd.gc, arrow_bits,                          arrow_width, arrow_height);
  57. :   XtAddCallback (arrow, XmNexposeCallback, redisplay, &arrow_pd);
  58. :   XtAddCallback (arrow, XmNresizeCallback, resize, &arrow_pd);
  59. :    /* add buttons and text widgets and stuff as above */
  60. :    return local_dialog;
  61. : } /* end create_dialog() */
  62. : Problem 1)
  63. : I can't seem to get a handle on the graphics contexts of the dialog.
  64. : I want to add a bit map and used Young p. 191 as an example.  create_pixmap()
  65. : and picmap_data are defined as he has it and this works fine at the main
  66. : level.
  67. : Things will compile fine, however when the call back is run I get:
  68. : X Error of failed request:  BadGC (invalid GC parameter)
  69. :   Major opcode of failed request:  56 (X_ChangeGC)
  70. :   Resource id in failed request:  0xf7800128
  71. :   Serial number of failed request:  465
  72. :   Current serial number in output stream:  515
  73. : and the program crashes.
  74. XtGetGC should only be used when you do not wish to change any of the GC values
  75. in the GC.  You specify all the values you care about and it finds or creates a
  76. GC having the specified values.  All other values are set to the default.
  77. Once you have obtained the GC using XtGetGC, you should not try to change any
  78. of it's values as this will potentially foul up other widgets.  
  79.  
  80. XCreateBitmapFromData and XReadBitmapFile both work with a pixmap of depth 1 andany functions you perform on them should use a GC created with a drawable of 
  81. depth 1.  The functions XCreatePixmapFromBitmapData and XCopyPlane should use a
  82. GC with the desired depth(probably 8).  
  83.  
  84. One common confussion you seem to have is that you must find THE GC for the 
  85. widget using XtGetGC.  XtGetGC is an XtFunction which allows for the caching of
  86. GC's so that if all widgets in your application have a background of red, and 
  87. a foreground of black, and all are on the same screen of the same display with
  88. the same depth, that only one GC is used by all widgets instead of having each
  89. widget create and use a seperate GC.  You could create a new GC if you wish to
  90. do your graphics processing.
  91.  
  92. Chris Atkins
  93. chris@ods.com
  94.