home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xgen / part03 / help.c < prev    next >
C/C++ Source or Header  |  1989-06-29  |  3KB  |  174 lines

  1. #include <stdio.h>
  2. #include <X11/IntrinsicP.h> 
  3. #include <X11/Intrinsic.h>
  4. #include <X11/StringDefs.h>
  5. #include <X11/Shell.h>
  6. #include <X11/Core.h>
  7. #include <X11/Text.h>
  8. #include <X11/AsciiText.h>
  9. #include <X11/AsciiTextP.h>
  10. #include "application.h"
  11.  
  12. extern int max_help_msg_width;
  13. extern int max_help_msg_height;
  14. extern int max_error_msg_width;
  15. extern int max_error_msg_height;
  16. extern XFontStruct *help_msg_font;
  17. extern XFontStruct *error_msg_font;
  18. extern Widget help_msg_widget;
  19. extern Widget error_msg_widget;
  20. extern Widget label_error_widget;
  21. extern Widget label_help_widget;
  22.  
  23.  
  24. void
  25. popup_help();
  26.  
  27. void
  28. button_help( w, closure, call_data)
  29. Widget w;
  30. caddr_t closure;
  31. caddr_t call_data;
  32. {
  33.     popup_help( closure );
  34. }
  35.  
  36. void
  37. help(w, event, params, num_params)
  38. Widget w;
  39. XEvent *event;
  40. String *params;
  41. Cardinal *num_params;
  42. {
  43.     char *help_string;
  44.     char *get_hash_help();
  45.  
  46.     help_string = get_hash_help(w);
  47.  
  48.     if( help_string == NULL )
  49.         help_string = "Sorry, I can't find any help for this item";
  50.  
  51.     popup_help( help_string);
  52. }
  53.  
  54. /*These routines will resize the message according to the      */
  55. /*string that will be displayed and replace the old string by  */
  56. /*the new one and pop the corresponding msgboard to the screen */
  57.  
  58. void
  59. popup_help(string)
  60. char *string;
  61. {
  62.     int width;
  63.     int i = 0;
  64.     int char_height,
  65.     height;
  66.     Arg args[15];
  67.     XtTextBlock text;
  68.     static char *old_string = "";
  69.     Widget help_widget;
  70.     Widget get_shell_address();
  71.  
  72.     if( string == NULL )
  73.         return;
  74.  
  75.     help_widget = get_shell_address("help");
  76.  
  77.     width = XTextWidth(help_msg_font, string, strlen(string));
  78.  
  79.     char_height = help_msg_font->ascent + help_msg_font->descent;
  80.  
  81.     height = (width/max_help_msg_width +2)* char_height;
  82.  
  83.     if (width > max_help_msg_width)
  84.     {
  85.         width = max_help_msg_width;
  86.         XtSetArg(args[i], XtNwidth,
  87.             max_help_msg_width); 
  88.         i++;
  89.         XtSetArg(args[i], XtNheight, height+2); 
  90.         i++;
  91.     }
  92.     else
  93.     {
  94.         XtSetArg(args[i], XtNwidth, width+2); 
  95.         i++;
  96.         XtSetArg( args[i], XtNheight, 2*char_height +2);  
  97.         i++;
  98.  
  99.     }
  100.  
  101.     XtSetValues( help_msg_widget, args, i);
  102.  
  103.     XtSetValues( label_help_widget, args, 1);
  104.  
  105.     text.firstPos = 0;
  106.     text.ptr = string;
  107.     text.length = strlen(string);
  108.  
  109.     popup(help_widget, "help");
  110.  
  111.     XtTextReplace( help_msg_widget, 0, strlen(old_string), &text);
  112.  
  113.     old_string  = string;
  114. }
  115.  
  116.  
  117. void
  118. popup_error(string)
  119. char *string;
  120. {
  121.     int width;
  122.     int i = 0;
  123.     int char_height,
  124.     height;
  125.     Arg args[15];
  126.     XtTextBlock text;
  127.     static char *old_string = "";
  128.     Widget error_widget;
  129.     Widget get_shell_address();
  130.  
  131.     if( string == NULL )
  132.         return;
  133.  
  134.     error_widget = get_shell_address("error");
  135.  
  136.     width = XTextWidth(error_msg_font, string, strlen(string));
  137.  
  138.     char_height = error_msg_font->ascent + error_msg_font->descent;
  139.  
  140.     height = (width/max_error_msg_width +2)* char_height;
  141.  
  142.     if (width > max_error_msg_width)
  143.     {
  144.         width = max_error_msg_width;
  145.         XtSetArg(args[i], XtNwidth,
  146.             max_error_msg_width); 
  147.         i++;
  148.         XtSetArg(args[i], XtNheight, height+2); 
  149.         i++;
  150.     }
  151.     else
  152.     {
  153.         XtSetArg(args[i], XtNwidth, width+2); 
  154.         i++;
  155.         XtSetArg( args[i], XtNheight, 2*char_height +2);  
  156.         i++;
  157.  
  158.     }
  159.  
  160.     XtSetValues( error_msg_widget, args, i);
  161.  
  162.     XtSetValues( label_error_widget, args, 1);
  163.  
  164.     text.firstPos = 0;
  165.     text.ptr = string;
  166.     text.length = strlen(string);
  167.  
  168.     popup(error_widget, "error");
  169.  
  170.     XtTextReplace( error_msg_widget, 0, strlen(old_string), &text);
  171.  
  172.     old_string  = string;
  173. }
  174.