Example #1
0
static int
errorhandler(Display *display, XErrorEvent *errorev)
{
    XGetErrorText(display, errorev->error_code, ErrorMessage, 1024);
    externalerror(ErrorMessage);
    return 0;
}
Example #2
0
static void
initcolors(GRAPH *graph)
{
    int i;
    static char *colornames[] = {   "black",    /* white */
                                    "white", "red", "blue",
                                    "orange", "green", "pink",
                                    "brown", "khaki", "plum",
                                    "orchid", "violet", "maroon",
                                    "turquoise", "sienna", "coral",
                                    "cyan", "magenta", "gold",
                                    "yellow", ""
    };

    XColor visualcolor, exactcolor;
    char buf[BSIZE_SP], colorstring[BSIZE_SP];
    int xmaxcolors = NUMCOLORS; /* note: can we get rid of this? */

    if (numdispplanes == 1) {
        /* black and white */
        xmaxcolors = 2;
        DEVDEP(graph).colors[0] = DEVDEP(graph).view->core.background_pixel;
        if (DEVDEP(graph).colors[0] == WhitePixel(display, DefaultScreen(display)))
            DEVDEP(graph).colors[1] = BlackPixel(display, DefaultScreen(display));
        else
            DEVDEP(graph).colors[1] = WhitePixel(display, DefaultScreen(display));

    } else {
        if (numdispplanes < NXPLANES)
            xmaxcolors = 1 << numdispplanes;

        for (i = 0; i < xmaxcolors; i++) {
            (void) sprintf(buf, "color%d", i);
            if (!cp_getvar(buf, CP_STRING, colorstring))
                (void) strcpy(colorstring, colornames[i]);
            if (!XAllocNamedColor(display,
                                  DefaultColormap(display, DefaultScreen(display)),
                                  colorstring, &visualcolor, &exactcolor)) {
                (void) sprintf(ErrorMessage,
                               "can't get color %s\n", colorstring);
                externalerror(ErrorMessage);
                DEVDEP(graph).colors[i] = i ? BlackPixel(display,
                                                         DefaultScreen(display))
                    : WhitePixel(display, DefaultScreen(display));
                continue;
            }
            DEVDEP(graph).colors[i] = visualcolor.pixel;

            /* MW. I don't need this, everyone must know what he is doing
               if (i > 0 &&
               DEVDEP(graph).colors[i] == DEVDEP(graph).view->core.background_pixel) {
               DEVDEP(graph).colors[i] = DEVDEP(graph).colors[0];
               } */

        }
        /* MW. Set Beackgroound here */
        XSetWindowBackground(display, DEVDEP(graph).window, DEVDEP(graph).colors[0]);

        /* if (DEVDEP(graph).colors[0] != DEVDEP(graph).view->core.background_pixel) {
        DEVDEP(graph).colors[0] = DEVDEP(graph).view->core.background_pixel;
        } */
    }

    for (i = xmaxcolors; i < NUMCOLORS; i++) {
        DEVDEP(graph).colors[i] = DEVDEP(graph).colors[i + 1 - xmaxcolors];
    }
}
Example #3
0
int WIN_NewViewport( GRAPH * graph)
{
   int      i;
   HWND     window;
   HDC      dc;
   TEXTMETRIC  tm;
   tpWindowData   wd;
   HMENU    sysmenu;

   /* test the parameters */
   if (!graph) return 1;

   /* initialize if not yet done */
   if (WIN_Init() != 0) {
      externalerror("Can't initialize GDI.");
      return(1);
   }

   /* allocate device dependency info */
   wd = calloc(1, sizeof(tWindowData));
   if (!wd) return 1;
   graph->devdep = (char *)wd;

   /* Create the window */
   i = GetSystemMetrics( SM_CYSCREEN) / 3;
   window = CreateWindow( WindowName, graph->plotname, WS_OVERLAPPEDWINDOW,
      0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
   if (!window) return 1;
   
   /* change the background color of all windows (both new and already plotted) 
      by assessing the registered window class */
   if (isblack)
      SetClassLong(window, GCLP_HBRBACKGROUND, (int)GetStockObject( BLACK_BRUSH));
   else
      SetClassLong(window, GCLP_HBRBACKGROUND, (int)GetStockObject( WHITE_BRUSH));	   
   
   
   wd->wnd = window;
   SetWindowLong( window, 0, (long)graph);

   /* show window */
   ShowWindow( window, SW_SHOWNORMAL);

   /* get the mask */
   GetClientRect( window, &(wd->Area));

   /* get the DC */
   dc = GetDC( window);
   wd->hDC = dc;

   /* set the Color Index */
   wd->ColorIndex = 0;

   /* still no flag */
   wd->PaintFlag = 0;
   wd->FirstFlag = 1;

   /* modify system menue */
   sysmenu = GetSystemMenu( window, FALSE);
   AppendMenu( sysmenu, MF_SEPARATOR, 0, NULL);
   AppendMenu( sysmenu, MF_STRING, ID_DRUCKEN,   STR_DRUCKEN);
   AppendMenu( sysmenu, MF_STRING, ID_DRUCKEINR, STR_DRUCKEINR);
   AppendMenu( sysmenu, MF_STRING, ID_HARDCOPY, STR_HARDCOPY);
   AppendMenu( sysmenu, MF_STRING, ID_HARDCOPY_BW, STR_HARDCOPY_BW);

   /* set default parameters of DC */
   SetBkColor( dc, ColorTable[0]);
   SetBkMode(  dc, TRANSPARENT );

   /* set font */
   SelectObject( dc, PlotFont);

   /* query the font parameters */
   if (GetTextMetrics( dc, &tm)) {
      graph->fontheight = tm.tmHeight;
      graph->fontwidth  = tm.tmAveCharWidth;
   }

   /* set viewport parameters */
   graph->viewport.height  = wd->Area.bottom;
   graph->viewport.width   = wd->Area.right;

   /* set absolute parameters */
   graph->absolute.xpos    = 0;
   graph->absolute.ypos    = 0;
   graph->absolute.width   = wd->Area.right;
   graph->absolute.height  = wd->Area.bottom;

   /* wait until the window is really there */
   WaitForIdle();

   /* ready */
   return(0);
}