HPlogo MPE/iX Developer's Kit Reference Manual Volume 2: HP 3000 MPE/iX Computer Systems > Chapter 4 CURSES

overlay overwrite

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

The overlay and overwrite routines are used to overlap or overwrite windows.

Syntax

   #include <curses.h>



   int overlay(WINDOW *srcwin, WINDOW *dstwin);

   int overwrite(WINDOW *srcwin, WINDOW *dstwin);

Parameters

srcwin

A pointer to the source window to be copied.

dstwin

A pointer to the destination window to be overlayed or overwritten.

Return Values

OK

Successful completion.

ERR

An error occurred.

Description

The overwrite() and overlay() routines copy srcwin to destwin. The source window (srcwin) and destination window (dstwin) do not have to be the same size.

The overwrite() routine copies all characters to dstwin; thus, destroying all previous contents of the window. The overlay() routine copies only nonblank characters, leaving blank characters intact. Thus, if the background character of the original window was set to something other than a blank, this original background could be preserved.

The example shown on the following pages illustrates how to use overwrite() to implement a pop-up dialog box.



  #include <curses.h>



  /*

   *   Pop-up a window on top of curscr.  If row and/or col

   *   are -1 then that dimension will be centered within

   *   curscr.  Return 0 for success or -1 if malloc() failed.

   *   Pass back the working window and the saved window for the

   *   pop-up.  The saved window should not be modified.

   */

  int

  popup(work, save, nrows, ncols, row, col)

  WINDOW **work, **save;

  int nrows, ncols, row, col;

  {

        int mr, mc;

        getmaxyx(curscr, mr, mc);

        /* Windows are limited to the size of curscr. */

        if (mr < nrows)

              nrows = mr;

        if (mc < ncols)

              ncols = mc;

        /* Center dimensions. */

        if (row == -1)

              row = (mr-nrows)/2;

        if (col == -1)

              col = (mc-ncols)/2;

        /* The window must fit entirely in curscr. */

        if (mr < row+nrows)

              row = 0;

        if (mc < col+ncols)

              col = 0;

        *work = newwin(nrows, ncols, row, col);

        if (*work == NULL)

              return (-1);

        if ((*save = dupwin(*work)) == NULL) {

              delwin(*work);

              return (-1);

        }

        overwrite(curscr, *save);

        return (0);

   }



   /*

    *   Restore the region covered by a popup window.

    *   Delete the working window and the saved window.





    *   This function is the complement to popup().  Return

    *   0 for success or -1 for an error.

    */

   int

   popdown(work, save)

   WINDOW *work, *save;

   {

         (void) overwrite(save, curscr);

         (void) delwin(save);

         (void) delwin(work);

         return (0);

   }



   /*

    *   Compute the size of a dialog box that would fit around

    *   the string.

    */

   void

   dialsize(str, nrows, ncols)

   char *str;

   int *nrows, *ncols;

   {

         int rows, cols, col;

         for (rows = 1, cols = col = 0; *str != ' '; ++str) {

               if (*str == '0) {

                     if (cols < col)

                           cols = col;

                     col = 0;

                     ++rows;

               } else {

                     ++col;

               }

        }

        if (cols < col)

              cols = col;

        *nrows = rows;

        *ncols = cols;

   }



   /*

    *   Write a string into a dialog box.

    */

   void

   dialfill(w, s)

   WINDOW *w;

   char *s;

   {

         int row;

         (void) wmove(w, 1, 1);

         for (row = 1; *s != ' '; ++s) {

               (void) waddch(w, *((unsigned char*) s));

               if (*s == '0)

                     wmove(w, ++row, 1);

         }

         box(w, 0, 0);

   }



   void

   dialog(str)

   char *str;

   {

        WINDOW *work, *save;

        int nrows, ncols, row, col;



        /* Figure out size of window. */



        dialsize(str, & nrows, & ncols);



        /* Create a centered working window with extra */

        /* room for a border. */



        (void) popup(& work, & save, nrows+2, ncols+2, -1, -1);



        /* Write text into the working window. */

        dialfill(work, str);



        /* Pause.  Remember that wgetch() will do a wrefresh() */

        /* for us. */

        (void) wgetch(work);



        /* Restore curscr and free windows. */

        (void) popdown(work, save);



        /* Redraw curscr to remove window from physical screen. */

        (void) doupdate();

   }

Implementation Considerations

Identical to XPG/3

See Also

copywin()

Portability

HP-UX, UNIX System V, XPG/3

Feedback to webmaster