|  | 
/* fichier source ph_40.c :
  ---------------------- */
/* this code uses the PHIGS WorkStation 233 and create N WS */
/* 
You can ignore the following message
  " X Toolkit Warning:
      Name: menubar
      Class: XmRowColumn
      Attempt to add wrong type child to a homogeneous RowColumn widget  "
   qui peuvent etre ignores. */
#include <stdio.h>
#include <stdlib.h>
#include <PHIGS/phigs.h>
#include <Xm/Xm.h>
#include <X11/Shell.h>
#include <Xm/MainW.h>
#include <Xm/RowColumn.h>
#include <Xm/CascadeB.h>
#include <Xm/BulletinB.h>
#include <Xm/PushB.h>
#include <Xm/PushBG.h>
#include <Mrm/MrmAppl.h>
/* Definitions pour titres et valeurs maximales */
#define PROGRAM_NAME  "Test colormap. WS n� %d"
#define PROGRAM_CLASS "TST_PHIGS"
#define ARG_MAX       10           /* Pour XtSetArg                           */
#define MAX_WS        33           /* Pour nombre maximal de WS PHIGS + 1     */
                                   /* L'index 0 utilise par le lanceur qui    */
                                   /* n'a pas de poste PHIGS associe          */
/* Part of code used by the customer to manipulate ws_id , to use it
and reuse after a close WS 
   ws_tab[i] == 0 ws free , ws_tab[i] == 1 ws used */
static Pint  ws_tab[MAX_WS - 1];        /* Workstation table                       */
static Pint  ws_tab_first[MAX_WS - 1];  /* Workstation table for open              */
static Pint  ws_tab_expose[MAX_WS - 1]; /* Workstation table for expose            */
static Pint  ws_id;                     /* Workstation identifier                  */
Pchar        conid[80];                 /* Connection identifier                   */
Pchar        wstype[80];                /* Workstation type                        */
static char  conid_str[]  = "PHIGSconid";  /* Pour setenv avant l'ouverture WS */
static char  wstype_str[] = "PHIGSwstype"; /* Pour setenv avant l'ouverture WS */
Arg          arg_list[ARG_MAX];         /* Pour XtSetArg                        */
Cardinal     arg_count;                 /* idem                                 */
Display      *display;                  /* X Display pointer                    */
Window       window;                    /* Window Id pour ouverture PHIGS       */
Widget       top_phigs_wid[MAX_WS];     /* Tableau des Widgets toplevel pour    */
                                        /* lanceur (index 0) et les WS PHIGS    */
Widget       main_wid[MAX_WS];          /* Tableau des Widgets MainWindow         */
Widget       phigs_wid[MAX_WS];         /* Tableau des Widgets BulletinBoard      */
Widget       menu_bar_wid[MAX_WS];      /* Tableau des Widgets MenuBar            */
Widget       exit_button_wid[MAX_WS];   /* Tableau des Widgets CascadeButton Exit */
Widget       phigs_output_wid[MAX_WS];  /* Tableau des Widgets PHIGS 233          */
Widget       exit_all, mem_size;        /* 2 CascadeButtons supplementaires pour  */
                                        /* lanceur: exit program et info taille   */
                                        /* memoire process                        */
XmString     label;                     /* Pour libelle des CascadeButtons        */
XtAppContext app_context;               /* Application Context                    */
/* Prototypes locales */
static void TstOuvrePhigsWs (Pint);
static void exit_cbk        (Widget, Pint, XmAnyCallbackStruct *);
static void mem_size_cbk    (Widget, Pint, XmAnyCallbackStruct *);
static void exit_all_cbk    (Widget, Pint, XmAnyCallbackStruct *);
static void expose_hnd      (Widget, Pint, XExposeEvent *);
/*  Exit from PHIGS */ 
static void exit_all_cbk (Widget widget, Pint ws_id, XmAnyCallbackStruct *data)
{
/*code removed*/
}
/* Write some information in a DECterm */
static void mem_size_cbk (Widget widget, Pint tag, XmAnyCallbackStruct *data)
{
/*code removed*/
}
/* Close Ws PHIGS. */
static void exit_cbk (Widget widget, Pint ws_id, XmAnyCallbackStruct *data)
{
/*code removed*/ 
}
/* Create a New WS . Function called after a click in the Push Button
   "Nouvelle WS". */
static void action_cbk (Widget widget, int tag, XmAnyCallbackStruct *data)
{
int found, i;
  found = 0;
  for (i = 0; i < MAX_WS - 1; i++)     /* On cherche un ID libre        */
  {
    if (ws_tab[i] == 0)
    {
      ws_tab[i] = 1;
      ws_id = i + 1;                   /* OK. i + 1 est le numero de WS */
      found = 1;
      break;
    }
  }
  if (found == 0)
  {
    printf ("Nombre de WS maximum atteint\n");
    return;
  }
  TstOuvrePhigsWs (ws_id);
}
/* Toplevel ---> Main Window
   Main Window ----> MenuBar ----> CascadeButton "Exit"
	|----------> WorkingArea -----> Id for widget PHIGS 
*/
static void expose_hnd (Widget widget, Pint ws_id, XExposeEvent *event)
{
Pint           error_ind, color_model, actual_size;
static Pint    tab_index[128];
static Pintlst indices = {128, tab_index};
Ppoint         rectangle[5*256];
Pfloat         x, y;
Pint           i, j, k, m;
Pcobundl       rep;
static int     first_time = 0;
Pint           rand, hexa_wstype;
Pescaperecord  out_esc_data, in_esc_data;
Pint           in_data_size;
Pint           out_data_size;
Pchar          **x_display_id;
Plong          *x_window_id;
  if (ws_tab_first[ws_id - 1] == 0)
  {
/* Le PHIGSconid */
    sprintf (conid, "%ld", phigs_wid[ws_id]);
    setenv (conid_str, conid, 1);
/* Le PHIGSwstype = "001000E9" 
		16 colors and type 233 */
    hexa_wstype = 0x001000e9;
    sprintf (wstype, "%ld", hexa_wstype);
    setenv (wstype_str, wstype, 1);
    if (first_time == 0)        
    {
      popenphigs (0, 0);
      first_time = 1;
    }
    popenws (ws_id, conid, hexa_wstype);
    /* Inquire the X display id and X window id */
    in_esc_data.nints = 1;
    in_esc_data.nfloats = 0;
    in_esc_data.nstrings = 0;
    in_esc_data.int_array = &ws_id;
    in_esc_data.float_array = (Pfloat *) NULL;
    in_esc_data.str_len_array = (Pint *) NULL;
    in_esc_data.str_ptr_array = (Pchar **) NULL;
    in_esc_data.npointers = 0;
    in_esc_data.ptr_ptr_array = (Pchar **) NULL;
    in_esc_data.nlongs = 0;
    in_esc_data.long_array = (Plong *) NULL;
    in_data_size = sizeof(Pescaperecord);
    out_esc_data.nints = 0;
    out_esc_data.nfloats = 0;
    out_esc_data.nstrings = 0;
    out_esc_data.int_array = (Pint *) NULL;
    out_esc_data.float_array = (Pfloat *) NULL;
    out_esc_data.str_len_array = (Pint *) NULL;
    out_esc_data.str_ptr_array = (Pchar **) NULL;
    out_esc_data.npointers = 1;
    out_esc_data.ptr_ptr_array = (Pchar **)(&display);
    out_esc_data.nlongs = 1;
    out_esc_data.long_array = (Plong *)(&window);
    out_data_size = sizeof(Pescaperecord);
    pescape (PPESC_INQ_WINDOW_IDS, &in_esc_data, in_data_size,
             &out_esc_data, &out_data_size);
    phigs_output_wid[ws_id] = XtWindowToWidget (display, window);
    XtAddEventHandler (phigs_output_wid[ws_id], ExposureMask | StructureNotifyMask, False,
                       expose_hnd, (XtPointer)ws_id);
    ws_tab_expose[ws_id - 1] = 0;
    ws_tab_first[ws_id - 1]  = 1;
  }
/* Open structure and draw 15 rectangles */
  if (ws_tab_expose[ws_id - 1] == 0)
  {
    ws_tab_expose[ws_id - 1] = 1;
    popenstruct (ws_id);			
      psetintstyle (PSOLID); 			
      rand = random () % 128 + 1;
      printf ("WS_ID : %d Facteur de repetition : %d\n", ws_id, rand);
      for (m = 0; m < rand; m++)
      {
        y = 0.0;
        for (i = 0; i < 3; i++)
        {
          x = 0.0;
          for (j = 0; j < 5; j++)
          {
            rectangle[0].x = rectangle[3].x = rectangle[4].x = x;
            rectangle[1].x = rectangle[2].x = x + 0.2;
            rectangle[0].y = rectangle[1].y = rectangle[4].y = y;
            rectangle[2].y = rectangle[3].y = y + 0.2;
            k = i * 5 + j + 1;
            psetintcolourind (k);
            pfillarea (4, rectangle);
            psetlinewidth (2.0);
            ppolyline (5, rectangle);
            x += 0.2;
          } 
          y += 0.3;
        } 
      }
    pclosestruct ();
    ppoststruct (ws_id, 1, 1.0);
    pupdatews (ws_id, PPERFORM);
  }
}
static void TstOuvrePhigsWs (Pint ws_id)
{
XmString label;
char     titre[80];
  if (ws_tab_first[ws_id - 1] == 0)
  {
    arg_count = 0;
    XtSetArg (arg_list[arg_count], XtNallowShellResize, TRUE); arg_count++;
    XtSetArg (arg_list[arg_count], XmNwidth,  (Dimension)300); arg_count++;
    XtSetArg (arg_list[arg_count], XmNheight, (Dimension)300); arg_count++;
    sprintf (titre, PROGRAM_NAME, ws_id);
    top_phigs_wid[ws_id] = XtAppCreateShell (titre, PROGRAM_CLASS,
                                             topLevelShellWidgetClass, display,
                                             arg_list, arg_count);
    arg_count = 0;
    main_wid[ws_id] = XmCreateMainWindow (top_phigs_wid[ws_id], "main",
                                          arg_list, arg_count);
    XtManageChild (main_wid[ws_id]);
    arg_count = 0;
    menu_bar_wid[ws_id] = XmCreateMenuBar (main_wid[ws_id], "menu_bar",
                                           arg_list, arg_count);
    XtManageChild (menu_bar_wid[ws_id]);
    label = XmStringCreateLtoR ("Exit", "");
    arg_count = 0;
    XtSetArg (arg_list[arg_count], XmNlabelString, label); arg_count++;
    exit_button_wid[ws_id] = XmCreatePushButton (menu_bar_wid[ws_id], "exitbutton",
                                                 arg_list, arg_count);
    XmStringFree (label);
    XtAddCallback (exit_button_wid[ws_id], XmNactivateCallback, exit_cbk, ws_id);
    XtManageChild (exit_button_wid[ws_id]);
    arg_count = 0;
    XtSetArg (arg_list[arg_count], XmNmarginWidth, 0); arg_count++;
    XtSetArg (arg_list[arg_count], XmNmarginHeight, 0); arg_count++;
    phigs_wid[ws_id] = XmCreateBulletinBoard (main_wid[ws_id], "phigs",
                                              arg_list, arg_count);
    XtManageChild (phigs_wid[ws_id]);
    XmMainWindowSetAreas (main_wid[ws_id], menu_bar_wid[ws_id],
                          NULL, NULL, NULL, phigs_wid[ws_id]);
    XtAddEventHandler (phigs_wid[ws_id], ExposureMask, False,
                       expose_hnd, (XtPointer)ws_id);
  }
  XtRealizeWidget (top_phigs_wid[ws_id]);
}
/* Initialisation du lanceur */
main (int argc, char *argv[])
{
int    min_cmaps, max_cmaps;
Screen *ecran;
  top_phigs_wid[0] = XtVaAppInitialize (&app_context, PROGRAM_CLASS, NULL, 0,
                                        &argc, argv, NULL, NULL);
  display = XtDisplay (top_phigs_wid[0]);
  main_wid[0] = XtVaCreateManagedWidget ("main_w", xmMainWindowWidgetClass,
                                         top_phigs_wid[0], NULL);
 
  menu_bar_wid[0] = XmCreateMenuBar (main_wid[0], "menubar", NULL, 0);
  label = XmStringCreateLtoR ("Nouvelle WS", "");
  arg_count = 0;
  XtSetArg (arg_list[arg_count], XmNlabelString, label); arg_count++;
  exit_button_wid[0] = XmCreateCascadeButton (menu_bar_wid[0], "actionbutton",
                                           arg_list, arg_count);
  XmStringFree (label);
  XtAddCallback (exit_button_wid[0], XmNactivateCallback, action_cbk, 0);
  XtManageChild (exit_button_wid[0]);
  label = XmStringCreateLtoR ("Taille Process", "");
  arg_count = 0;
  XtSetArg (arg_list[arg_count], XmNlabelString, label); arg_count++;
  mem_size = XmCreateCascadeButton (menu_bar_wid[0], "memsize",
                                 arg_list, arg_count);
  XmStringFree (label);
  XtAddCallback (mem_size, XmNactivateCallback, mem_size_cbk, 0);
  XtManageChild (mem_size);
  label = XmStringCreateLtoR ("Exit Test", "");
  arg_count = 0;
  XtSetArg (arg_list[arg_count], XmNlabelString, label); arg_count++;
  exit_all = XmCreateCascadeButton (menu_bar_wid[0], "exitall",
                                 arg_list, arg_count);
  XmStringFree (label);
  XtAddCallback (exit_all, XmNactivateCallback, exit_all_cbk, 0);
  XtManageChild (exit_all);
  XtManageChild (menu_bar_wid[0]);
  XtRealizeWidget (top_phigs_wid[0]);
  XtAppMainLoop (app_context);
}
    
 |