bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug With wborder_set and windows / panels ..


From: Ben Duncan
Subject: Bug With wborder_set and windows / panels ..
Date: Fri, 02 Oct 2009 10:05:41 -0500
User-agent: Thunderbird 2.0.0.23 (X11/20090812)

Ok, on UTF-8 I find you must use wborder_set to use UTF (answer to my earlier).
HOWEVER using panels,  windows and wborder_set really screws things up ...

See attached test program ... and the print_wina function ...



--
Ben Duncan - Business Network Solutions, Inc. 336 Elton Road  Jackson MS, 39212
"Never attribute to malice, that which can be adequately explained by stupidity"
       - Hanlon's Razor
/* Test Wide Window characters for UTF-8  
 * Compile with : gcc -lncursesw -lpanelw -o testwidewin testwidewin.c
*/

#include <locale.h>

#include <curses.h>
#include <panel.h>
#include <stdlib.h>
#include <string.h>
#define ENTER 10
#define ESCAPE 27

#define WIDTH 40
#define HEIGHT 15

int startx = 0;
int starty = 0;

/* Thick Border Colors */

  wchar_t thk_boxupright [] = { 0x2513, 0x00 } ;
  wchar_t thk_boxupleft [] = { 0x250f, 0x00 } ;
  wchar_t thk_boxlowleft [] = { 0x2517, 0x00 } ;
  wchar_t thk_boxlowright [] = { 0x251B, 0x00 } ;
  wchar_t thk_boxvertline [] = { 0x2503, 0x00 } ;
  wchar_t thk_boxhorzline [] = { 0x2501, 0x00 } ;

/* Thin Border Colors */

  wchar_t thn_boxupright [] = { 0x2510, 0x00 } ;
  wchar_t thn_boxupleft [] = { 0x250c, 0x00 } ;
  wchar_t thn_boxlowleft [] = { 0x2514, 0x00 } ;
  wchar_t thn_boxlowright [] = { 0x2518, 0x00 } ;
  wchar_t thn_boxvertline [] = { 0x2502, 0x00 } ;
  wchar_t thn_boxhorzline [] = { 0x2500, 0x00 } ;

/* WIDE test characters to display */
  wchar_t empty_wide [] = { 0x0000, 0x00 } ;
  wchar_t wide_char_t [] = { 0x23d0, 0x00 } ;

  wchar_t lightgrey [] = { 0x2591, 0x00 } ;
  wchar_t mediumgrey [] = { 0x2592, 0x00 } ;
  wchar_t darkgrey [] = { 0x2593, 0x00 } ;
  wchar_t Xbox [] = { 0x2327, 0x00 } ;
  wchar_t bboxcheck [] = { 0x2611, 0x00 } ;
  wchar_t bboxx [] = { 0x2612, 0x00 } ;
  wchar_t rightarrow1 [] = { 0x27a9 , 0x00 } ;
  wchar_t rightarrow2 [] = { 0x27aa , 0x00 } ;
  wchar_t dashedc [] = { 0x2026 , 0x00 } ;


char *choicesa[] = { "Choice A1",
  "Choice A2",
  "Choice A3",
  "Choice A4",
  "Exit",
};

char *choicesb[] = { "Choice B1",
  "Choice B2",
  "Choice B3",
  "Choice B4",
  "Choice B5",
  "Choice B6",
  "Choice B7",
  "Choice B4",
  "Exit",
};

int a_choices = sizeof ( choicesa ) / sizeof ( char * );
int b_choices = sizeof ( choicesb ) / sizeof ( char * );


void print_wina( WINDOW * menu_win, int highlight );
void print_winb( WINDOW * menu_win, int highlight );


void init_curses (  )
{
  initscr (  );
  start_color (  );
  init_pair ( 1, COLOR_WHITE, COLOR_BLUE );
  init_pair ( 2, COLOR_BLUE, COLOR_WHITE );
  init_pair ( 3, COLOR_RED, COLOR_WHITE );
  curs_set ( 0 );
  noecho (  );
  keypad ( stdscr, TRUE );
}

int main (  )
{
  int key;

  setlocale(LC_ALL, "");

  unsigned short testint = 0x2611 ;
  char testchar [] = { 0x26 , 0x11 } ;
  unsigned short COLOR_gains [3] = { 0xdc, 0xdc, 0xdc } ;


  WINDOW *mywin_a ;
  WINDOW *mywin_b ;

  PANEL *mypan_a ;
  PANEL *mypan_b ;

  init_curses (  );

  bkgd ( COLOR_PAIR ( 1 ) );

  move ( 2, 1 );
  printw ( "Let us test wide characters ... " );
  printw ( "any key ends ...." );

  /* SPECIAL characters ...
  move ( 4 , 2 ) ; 
  printw ( "Special char is : " ) ; 

  move ( 4 , 30 ) ; 
  addwstr ( wide_char_t ) ; 

*/

  move ( 4 , 2 ) ; 
  printw ( "Light grey is : " ) ; 
  move ( 4 , 30 ) ; 
  addwstr ( lightgrey ) ; 

  move ( 5 , 2 ) ; 
  printw ( "medium grey is : " ) ; 
  move ( 5 , 30 ) ; 
  addwstr ( mediumgrey ) ; 

  move ( 6 , 2 ) ; 
  printw ( "dark grey is : " ) ; 
  move ( 6 , 30 ) ; 
  addwstr ( darkgrey ) ; 

  move ( 7 , 2 ) ; 
  printw ( "Xbox Char is : " ) ; 
  move ( 7 , 30 ) ; 
  addwstr ( Xbox ) ; 

  move ( 8 , 2 ) ; 
  printw ( "BBoxchk Char is : " ) ; 
  move ( 8 , 30 ) ; 
  addwstr ( bboxcheck ) ; 
  move ( 9 , 2 ) ; 
  printw ( "bboxx Char is : " ) ; 
  move ( 9 , 30 ) ; 
  addwstr ( bboxx ) ; 
  move ( 10 , 2 ) ; 
  printw ( "R Arrow 1 Char is : " ) ; 
  move ( 10 , 30 ) ; 
  addwstr ( rightarrow1 ) ; 
  move ( 11 , 2 ) ; 
  printw ( "R Arrow 2 Char is : " ) ; 
  move ( 11 , 30 ) ; 
  addwstr ( rightarrow2 ) ; 

  move ( 12 , 2 ) ; 
  printw ( "DASHED Char is : " ) ; 
  move ( 12 , 30 ) ; 
  addwstr ( dashedc  ) ; 
  move ( 12 , 31 ) ; 
  addwstr ( dashedc ) ; 
  move ( 12 , 32 ) ; 
  addwstr ( dashedc ) ; 

  move ( 18 , 2 ) ; 
  printw ( "whcar_t size  is : %i, testchar is %i  value testint %i " , 
          sizeof( empty_wide), sizeof (testchar) , testint ) ; 

  memset ( empty_wide ,  0,  8 );
  memcpy ( empty_wide, &testint, 2 ) ;
  move ( 13 , 2 ) ; 
  printw ( "empty_wide Char is : " ) ; 
  move ( 13 , 30 ) ; 
  addwstr ( empty_wide ) ; 

  testint++ ;
  memcpy ( empty_wide, &testint, 2 ) ;
  move ( 14 , 2 ) ; 
  printw ( "empty_wide Char +1 is : " ) ; 
  move ( 14 , 30 ) ; 
  addwstr ( empty_wide ) ; 


  refresh (  );
  key = getch (  );

/* BOX Window TEST */

  mywin_a = newwin( 8, 30, 4, 10 );
  print_wina ( mywin_a, 1 );
  mypan_a = new_panel( mywin_a ) ;
  update_panels ( ) ;
  doupdate ( ) ;

  key = getch (  );

  mywin_b = newwin ( 12, 30, 8, 14 );
  print_winb ( mywin_b, 1 );
  mypan_b = new_panel( mywin_b ) ;
  update_panels ( ) ;
  doupdate ( ) ;

  key = getch (  );
  hide_panel (mypan_b) ;
  update_panels ( ) ;
  doupdate ( ) ;

  key = getch (  );
  hide_panel (mypan_a) ;
  update_panels ( ) ;
  doupdate ( ) ;

  key = getch (  );

/* Show the PANEl B */

  show_panel (mypan_b) ;
  update_panels ( ) ;
  doupdate ( ) ;

  key = getch (  );

  hide_panel (mypan_b) ;
  update_panels ( ) ;
  doupdate ( ) ;

  key = getch (  );
  
  endwin (  );
  return 0;
}

void print_wina ( WINDOW * win, int highlight )
{
  int x, y, i, err;

  x = 2;
  y = 2;

/********************************************************
 * TEST UTF Border characters for NORMAL Border test    *
 * To see normal function comment out wborder-set       *
 * and uncomment box. To see wborder-set screw up,      *
 * just leave things be.                                *
 ****************************************************** */

/*
  box ( win, 0, 0 );
*/

 err = wborder_set(win , thn_boxvertline, thn_boxvertline,
          thn_boxhorzline, thn_boxhorzline ,
          thn_boxupleft, thn_boxupright,
          thn_boxlowleft, thn_boxlowright ) ;

  if ( err == ERR )
     {
         move ( 22 , 2 ) ; 
         printw ( "WINDOW A BORDER ERROR" ) ; 
         exit(-1) ;
     }


  for ( i = 0; i < a_choices; ++i )
    {
      if ( highlight == i + 1 )
        {
          wattron ( win, A_REVERSE );
          mvwprintw ( win, y, x, "%s", choicesa[i] );
          wattroff ( win, A_REVERSE );
        }
      else
        mvwprintw ( win, y, x, "%s", choicesa[i] );
      ++y;
    }
}

void print_winb ( WINDOW * win, int highlight )
{
  int x, y, i;

  x = 2;
  y = 2;
  box ( win, 0, 0 );
  for ( i = 0; i < b_choices; ++i )
    {
      if ( highlight == i + 1 )
        {
          wattron ( win, A_REVERSE );
          mvwprintw ( win, y, x, "%s", choicesb[i] );
          wattroff ( win, A_REVERSE );
        }
      else
        mvwprintw ( win, y, x, "%s", choicesb[i] );
      ++y;
    }
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]