libyui-ncurses  2.44.1
 All Classes Functions Variables
NCStyleDef.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: NCStyleDef.cc
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #include <iostream>
26 #include <fstream>
27 #include <vector>
28 #include <list>
29 
30 
31 #define YUILogComponent "ncurses"
32 #include <yui/YUILog.h>
33 #include "NCurses.h"
34 #include "NCstyle.h"
35 
36 
38 {
39 
40 public:
41 
42  // Self reference
43  static NCStyleDef * NCStyleDef_p;
44 
45  // Reference to class NCstyle
46  NCstyle & NCstyle_C;
47 
48  // Master panel
49  NCursesPanel p;
50 
51  // draw panel frame in move mode or plain
52  void pbox( bool on = false );
53 
54  // move panel interactive or determined by key
55  int movePad( int key = -1 );
56 
57  static const NCursesPanel & pad() { return NCStyleDef_p->p; }
58 
59  static void refresh() { NCStyleDef_p->p.refresh(); }
60 
61  static int movepad( int key = -1 ) { return NCStyleDef_p->movePad( key ); }
62 
63 
64  // Example popup is somwhat special. It's handmade, so we habe to
65  // keep it in sync when attributes change.
66 
67  enum ExMode { EX_OFF, EX_ON, EX_TOGGLE, EX_UPDATE };
68 
69  static void showex( ExMode mode );
70 
71  // Advise NCstyle to fake attributes, i.e. always return the set we currently process
72  static void fakestyle( NCstyle::StyleSet style )
73  {
74  NCStyleDef_p->NCstyle_C.fakestyle( style );
75 
76  if ( style != NCstyle::MaxStyleSet )
77  {
78  NCStyleDef_p->doshowset( NCStyleDef_p->wSet.cset, true );
79  showex( EX_UPDATE );
80  }
81  else
82  {
83  showex( EX_OFF );
84  }
85  }
86 
87  // to be called to reflect changed attributes on screen
88  static void attrchanged()
89  {
90  NCurses::Redraw();
91  showex( EX_UPDATE );
92  }
93 
94  // SetTypes handled by struct Wset.
95 
96  enum SetType
97  {
98  Global = 0,
99  DialogBorder,
100  DialogBorderActive,
101  DialogText,
102  Widget,
103  WidgetActive,
104  FrameWidget,
105  FrameWidgetActive,
106  List,
107  ListActive,
108  RichText,
109  ProgressBar,
110  // last entry
111  MaxSetType
112  };
113 
114  static std::string dumpName( SetType a )
115  {
116 #define PRT(t) case t: return #t;
117 
118  switch ( a )
119  {
120  PRT( Global );
121  PRT( DialogBorder );
122  PRT( DialogBorderActive );
123  PRT( DialogText );
124  PRT( Widget );
125  PRT( WidgetActive );
126  PRT( FrameWidget );
127  PRT( FrameWidgetActive );
128  PRT( List );
129  PRT( ListActive );
130  PRT( RichText );
131  PRT( ProgressBar );
132 
133  case MaxSetType:
134  break;
135  }
136 
137  return "unknown";
138 
139 #undef PRT
140  }
141 
142  // Aset serves as menu entry for struct Wchattr.
143  // Any modification of the associated chtype is handled here.
144 
145  struct Aset
146  {
147 
148 private:
149  chtype * attr_p;
150 
151 public:
152  std::string label;
153  Aset( chtype & ch, const std::string & l ) : attr_p( &ch ), label( l )
154  {}
155 
156  chtype attr() const { return *attr_p; }
157 
158  chtype textattr() const { return attr() & ~NCattribute::char_mask; }
159 
160  void setBg( bool prev ) { NCattribute::setBg( *attr_p, NCattribute::getBg( *attr_p ) + ( prev ? -1 : 1 ) ); }
161 
162  void setFg( bool prev ) { NCattribute::setFg( *attr_p, NCattribute::getFg( *attr_p ) + ( prev ? -1 : 1 ) ); }
163 
164  void toggleStyle( chtype sty ) { NCattribute::toggleStyle( *attr_p, sty ); }
165 
166  void setStyle( chtype sty ) { NCattribute::setStyle( *attr_p, sty ); }
167 
168  void setChar( chtype sty ) { NCattribute::setChar( *attr_p, sty ); }
169  };
170 
171  // Retrieve appropriate chtype from NCstyle
172  const chtype & attr( NCstyle::STglobal a )
173  {
174  return NCstyle_C.getStyle( NCstyle_C.fakestyle_e ).attr( a );
175  }
176 
177  const chtype & attr( NCstyle::STlocal a )
178  {
179  return NCstyle_C.getStyle( NCstyle_C.fakestyle_e ).attr( a );
180  }
181 
182  // Build the Aset std::vector associated with a SetType and assing it to struct Wchattr.
183  void doshowset( SetType a, bool reset = false );
184 
185  static void showset( SetType a )
186  {
187  NCStyleDef_p->doshowset( a );
188  }
189 
190  // queryCharEnt serves as menu entry for the ACS char popoup in queryChar()
191  // queryChar(). Used in struct Wchattr.
192 
194  {
195  std::string l;
196  chtype c;
197  queryCharEnt( std::string L, chtype C ) { l = L; c = C; }
198  };
199 
200  static chtype queryChar( int column = 0, chtype selbg = A_REVERSE );
201 
202  // Show details of Wchattr's current item (fg/bg and attributes)
203 
204  void doshowstat( const Aset & a ) { wChstat.stat( a ); }
205 
206  static void showstat( const Aset & a )
207  {
208  NCStyleDef_p->doshowstat( a );
209  }
210 
211  static const char * dumpColor( short c )
212  {
213  switch ( c )
214  {
215  case -1:
216  return "-1";
217  break;
218 
219  case COLOR_BLACK:
220  return "bk";
221  break;
222 
223  case COLOR_RED:
224  return "re";
225  break;
226 
227  case COLOR_GREEN:
228  return "gr";
229  break;
230 
231  case COLOR_YELLOW:
232  return "ye";
233  break;
234 
235  case COLOR_BLUE:
236  return "bl";
237  break;
238 
239  case COLOR_MAGENTA:
240  return "ma";
241  break;
242 
243  case COLOR_CYAN:
244  return "cy";
245  break;
246 
247  case COLOR_WHITE:
248  return "wh";
249  break;
250  }
251 
252  return "??";
253  }
254 
255 
256  /**
257  * SubWin: base class for the windows used
258  **/
259  struct SubWin
260  {
261  static const int taglen = 7;
262  NCursesWindow w;
263  std::string tag;
264  chtype changestyle;
265  SubWin( std::string T, NCursesWindow & P, int H, int W, int L, int C )
266  : w( P, H, W, L, C, 'r' )
267  , tag( std::string( "<" ) + T + ">" )
268  {
269  changestyle = A_NORMAL;
270  }
271 
272  virtual ~SubWin() {}
273 
274  virtual void draw( bool immediate = false )
275  {
276  w.syncup();
277 
278  if ( immediate )
279  refresh();
280  }
281 
282  virtual int dtag()
283  {
284  if ( tag.size() > 2 )
285  {
286  w.printw( 0, 0, "%-*.*s", taglen, taglen, tag.c_str() );
287  return w.width() - taglen;
288  }
289 
290  w.move( 0, 0 );
291 
292  return w.width();
293  }
294 
295  virtual int change()
296  {
297  enterchange();
298  bool continue_bi = true;
299  int in = -1;
300 
301  do
302  {
303  switch (( in = getch() ) )
304  {
305  case -1:
306  case KEY_ESC:
307  case KEY_TAB:
308  case KEY_RETURN:
309  in = -1; // no reconsume
310 
311  case KEY_F( 1 ):
312  case KEY_F( 2 ):
313  case KEY_F( 3 ):
314  case KEY_F( 4 ):
315  case KEY_F( 5 ):
316  case KEY_F( 6 ):
317  case KEY_F( 7 ):
318  case KEY_F( 8 ):
319  case KEY_F( 9 ):
320  case KEY_F( 10 ):
321  continue_bi = false;
322  break;
323 
324  default:
325  handle( in );
326  break;
327  }
328  }
329  while ( continue_bi );
330 
331  leavechange();
332 
333  return in;
334  }
335 
336  virtual void enterchange()
337  {
338  changestyle = A_REVERSE;
339  w.bkgd( changestyle );
340  draw( true );
341  }
342 
343  virtual void leavechange()
344  {
345  changestyle = A_NORMAL;
346  w.bkgd( changestyle );
347  draw( true );
348  }
349 
350  virtual void handle( int in )
351  {
352  }
353  };
354 
355 
356  /**
357  * Wstyle: Selection of the current NCstyle::StyleSet to process
358  **/
359  struct Wstyle : public SubWin
360  {
361  NCstyle::StyleSet cset;
362  Wstyle( std::string T, NCursesWindow & P, int H, int W, int L, int C )
363  : SubWin( T, P, H, W, L, C )
364  {
365  cset = ( NCstyle::StyleSet )( 0 );
366  }
367 
368  virtual void draw( bool immediate = false )
369  {
370  int len = dtag();
371  w.printw( "%-*.*s", len, len, NCstyle::dumpName( cset ).c_str() );
372 
373  if ( cset == 0 )
374  w.addch( 0, 2, '-' );
375 
376  if ( cset == NCstyle::MaxStyleSet - 1 )
377  w.addch( 0, 4, '-' );
378 
379  SubWin::draw( immediate );
380  }
381 
382  virtual void handle( int in )
383  {
384  switch ( in )
385  {
386  case KEY_UP:
387 
388  if ( cset > 0 )
389  {
390  cset = ( NCstyle::StyleSet )( cset - 1 );
391  draw( true );
392  fakestyle( cset );
393  }
394  break;
395 
396  case KEY_DOWN:
397 
398  if ( cset + 1 < NCstyle::MaxStyleSet )
399  {
400  cset = ( NCstyle::StyleSet )( cset + 1 );
401  draw( true );
402  fakestyle( cset );
403  }
404  break;
405  }
406  }
407  };
408 
409 
410  /**
411  * Wset: Selection of the current attribute std::set to process
412  **/
413  struct Wset : public SubWin
414  {
415  SetType cset;
416  Wset( std::string T, NCursesWindow & P, int H, int W, int L, int C )
417  : SubWin( T, P, H, W, L, C )
418  {
419  cset = ( SetType )( 0 );
420  }
421 
422  virtual void draw( bool immediate = false )
423  {
424  int len = dtag();
425  w.printw( "%-*.*s", len, len, dumpName( cset ).c_str() );
426 
427  if ( cset == 0 )
428  w.addch( 0, 2, '-' );
429 
430  if ( cset == MaxSetType - 1 )
431  w.addch( 0, 4, '-' );
432 
433  SubWin::draw( immediate );
434  }
435 
436  virtual void handle( int in )
437  {
438  switch ( in )
439  {
440  case KEY_UP:
441 
442  if ( cset > 0 )
443  {
444  cset = ( SetType )( cset - 1 );
445  draw( true );
446  showset( cset );
447  }
448 
449  break;
450 
451  case KEY_DOWN:
452 
453  if ( cset + 1 < MaxSetType )
454  {
455  cset = ( SetType )( cset + 1 );
456  draw( true );
457  showset( cset );
458  }
459 
460  break;
461  }
462  }
463  };
464 
465 
466  /**
467  * Wchattr: handle modification of the current attribute std::set.
468  **/
469  struct Wchattr : public SubWin
470  {
471  std::vector<Aset> aset;
472  unsigned fitem;
473  unsigned citem;
474  Wchattr( std::string T, NCursesWindow & P, int H, int W, int L, int C )
475  : SubWin( T, P, H, W, L, C )
476  {
477  fitem = citem = 0;
478  }
479 
480  virtual void draw( bool immediate = false )
481  {
482  w.box();
483  dtag();
484  drawTable( immediate );
485  }
486 
487  virtual void handle( int in )
488  {
489  if ( !aset.size() )
490  return;
491 
492  bool redraw = true;
493 
494  bool redrawall = true;
495 
496  switch ( in )
497  {
498  case KEY_UP:
499 
500  if ( citem )
501  {
502  --citem;
503  redrawall = false;
504  }
505 
506  break;
507 
508  case KEY_DOWN:
509 
510  if ( citem + 1 < aset.size() )
511  {
512  ++citem;
513  redrawall = false;
514  }
515 
516  break;
517 
518  case KEY_LEFT:
519  case KEY_RIGHT:
520  movepad( in );
521  break;
522 
523  case KEY_PPAGE:
524  aset[citem].setBg( true );
525  break;
526 
527  case KEY_NPAGE:
528  aset[citem].setBg( false );
529  break;
530 
531  case KEY_HOME:
532  aset[citem].setFg( true );
533  break;
534 
535  case KEY_END:
536  aset[citem].setFg( false );
537  break;
538 
539  case KEY_IC:
540  case 'b':
541  aset[citem].toggleStyle( A_BOLD );
542  break;
543 
544  case KEY_DC:
545  case 'n':
546  aset[citem].setStyle( A_NORMAL );
547  break;
548 
549  case 'l':
550  aset[citem].toggleStyle( A_BLINK );
551  break;
552 
553  case 's':
554  aset[citem].toggleStyle( A_STANDOUT );
555  break;
556 
557  case 'u':
558  aset[citem].toggleStyle( A_UNDERLINE );
559  break;
560 
561  case 'r':
562  aset[citem].toggleStyle( A_REVERSE );
563  break;
564 
565  case 'd':
566  aset[citem].toggleStyle( A_DIM );
567  break;
568 
569  case 'i':
570  aset[citem].toggleStyle( A_INVIS );
571  break;
572 
573  case 'a':
574  {
575  chtype ach = queryChar( pad().begx() + 5, aset[citem].textattr() );
576 
577  if ( ach != ( chtype ) - 1 )
578  aset[citem].setChar( ach );
579  }
580 
581  break;
582 
583  default:
584  redraw = redrawall = false;
585  break;
586  }
587 
588  if ( redraw )
589  drawTable( true );
590 
591  if ( redrawall )
592  attrchanged();
593  }
594 
595  void set( std::vector<Aset> & nset, bool reset = false )
596  {
597  aset.swap( nset );
598  draw( true );
599  }
600 
601  void drawTable( bool immediate = false )
602  {
603  unsigned t = w.height() - 1;
604  unsigned high = ( t - 1 );
605  unsigned spot = high / 2;
606  unsigned l = 1;
607 
608  if ( !aset.size() )
609  citem = 0;
610  else if ( citem >= aset.size() )
611  citem = aset.size() - 1;
612 
613  if ( high >= aset.size() || citem <= spot )
614  {
615  fitem = 0;
616  }
617  else
618  {
619  fitem = citem - spot;
620 
621  if ( fitem + high >= aset.size() )
622  fitem = aset.size() - high;
623  }
624 
625  for ( unsigned i = fitem; l < t; ++i, ++l )
626  {
627  drawItemAt( l, i );
628  }
629 
630  if ( !aset.size() )
631  {
632  int len = w.width() - 2;
633  w.bkgdset( changestyle );
634  w.printw( 1, 1, "%-*.*s", len, len, "<empty>" );
635  }
636 
637  w.bkgdset( changestyle );
638 
639  SubWin::draw( immediate );
640  }
641 
642  void drawItemAt( unsigned line, unsigned num )
643  {
644  int len = w.width() - 4;
645 
646  if ( num < aset.size() )
647  {
648  w.bkgdset( changestyle );
649 
650  if ( num == citem )
651  {
652  w.addstr( line, 1, "->" );
653  showstat( aset[num] );
654  }
655  else
656  {
657  w.addstr( line, 1, " " );
658  }
659 
660  w.bkgdset( aset[num].attr() );
661 
662  w.printw( line, 3, "%-*.*s", len, len, "" );
663  w.bkgdset( aset[num].textattr() );
664  w.addstr( line, 3, aset[num].label.c_str(), len );
665  }
666  else
667  {
668  w.bkgdset( changestyle );
669  w.printw( line, 1, "%-*.*s", len + 2, len + 2, "" );
670  }
671  }
672  };
673 
674 
675  /**
676  * Wchstat: show current attributes definition
677  **/
678  struct Wchstat : public SubWin
679  {
680  Wchstat( std::string T, NCursesWindow & P, int H, int W, int L, int C )
681  : SubWin( T, P, H, W, L, C )
682  {
683  }
684 
685  virtual int change() { return -1; }
686 
687  virtual void draw( bool immediate = false )
688  {
689  w.bkgdset( A_NORMAL );
690  w.clear();
691  SubWin::draw( immediate );
692  }
693 
694  void stat( const Aset & a )
695  {
696  static char buf[1024];
697  int len = w.width() - 2;
698  chtype ch = a.attr();
699  w.bkgdset( a.attr() );
700  w.clear();
701  w.bkgdset( a.textattr() );
702  w.box();
703  w.addstr( 0, 1, a.label.c_str(), len );
704  sprintf( buf, "%s/%s %c%c%c%c%c%c%c %c%3u",
705  dumpColor( NCattribute::fg_color_of( ch ) ),
706  dumpColor( NCattribute::bg_color_of( ch ) ),
707  ( ch&A_INVIS ? 'i' : '.' ),
708  ( ch&A_BOLD ? 'b' : '.' ),
709  ( ch&A_DIM ? 'd' : '.' ),
710  ( ch&A_BLINK ? 'l' : '.' ),
711  ( ch&A_REVERSE ? 'r' : '.' ),
712  ( ch&A_UNDERLINE ? 'u' : '.' ),
713  ( ch&A_STANDOUT ? 's' : '.' ),
714  ( ch&A_ALTCHARSET ? 'A' : '.' ),
715  ( unsigned )( ch&A_CHARTEXT )
716  );
717  w.addstr( 1, 1, buf, len );
718  SubWin::draw( true );
719  }
720  };
721 
722 
723  /**
724  * Wex: popup and down the example Dialog
725  **/
726  struct Wex : public SubWin
727  {
728  SetType cset;
729  Wex( std::string T, NCursesWindow & P, int H, int W, int L, int C )
730  : SubWin( T, P, H, W, L, C )
731  {
732  showex( EX_OFF );
733  }
734 
735  virtual void draw( bool immediate = false )
736  {
737  int len = dtag();
738  w.printw( "%-*.*s", len, len, "Example Dialog" );
739  SubWin::draw( immediate );
740  }
741 
742  virtual int change()
743  {
744  showex( EX_TOGGLE );
745  return -1;
746  }
747  };
748 
749 
750  //
751  // Construct the panel and widgets
752  //
753 
754  Wstyle wStyle;
755  Wset wSet;
756  Wchstat wChstat;
757  Wchattr wChattr;
758  Wex wEx;
759 
760  NCStyleDef( NCstyle & style )
761  : NCstyle_C( style )
762  , p( 19, 30, NCurses::lines() - 19, 1 )
763  , wStyle( "F1/2", p, 1, 28, 1, 1 )
764  , wSet( "F3/4", p, 1, 28, 2, 1 )
765  , wChstat( "", p, 3, 28, 3, 1 )
766  , wChattr( "", p, 11, 28, 6, 1 )
767  , wEx( "F6", p, 1, 28, 17, 1 )
768  {
769  NCStyleDef_p = this;
770  pbox();
771  wStyle.draw();
772  wSet.draw();
773  wChstat.draw();
774  wChattr.draw();
775  wEx.draw();
776  }
777 
778  ~NCStyleDef() { NCStyleDef_p = 0; }
779 
780  void changeStyle();
781 
782  void saveStyle();
783 
784  // that's the way the chtype is saved to file
785  std::ostream & dumpChtype( std::ostream & str, const chtype & ch )
786  {
787  static chtype mask = A_STANDOUT | A_UNDERLINE | A_REVERSE | A_BLINK | A_DIM | A_BOLD | A_INVIS;
788  chtype base = ch & ~mask;
789  chtype style = ch & mask;
790 #define PRTIF(S) if ( style & S ) str << "|" << #S
791  str << base;
792  PRTIF( A_STANDOUT );
793  PRTIF( A_UNDERLINE );
794  PRTIF( A_REVERSE );
795  PRTIF( A_BLINK );
796  PRTIF( A_DIM );
797  PRTIF( A_BOLD );
798  PRTIF( A_INVIS );
799 #undef PRTIF
800  return str;
801  }
802 
803  void restoreStyle();
804 
805 
806  /**
807  * helper struct to std::map strings to NCstyle enum values
808  **/
809  struct lookupIdx
810  {
811  NCstyle::STglobal glob;
812  NCstyle::STlocal loc;
813  lookupIdx() { glob = NCstyle::MaxSTglobal; loc = NCstyle::MaxSTlocal; }
814 
815  lookupIdx( NCstyle::STglobal g ) { glob = g; loc = NCstyle::MaxSTlocal; }
816 
817  lookupIdx( NCstyle::STlocal l ) { glob = NCstyle::MaxSTglobal; loc = l; }
818 
819  bool isLoc() const { return glob == NCstyle::MaxSTglobal && loc != NCstyle::MaxSTlocal; }
820 
821  bool isGlob() const { return glob != NCstyle::MaxSTglobal && loc == NCstyle::MaxSTlocal; }
822 
823  bool isUnknown() const { return glob == NCstyle::MaxSTglobal && loc == NCstyle::MaxSTlocal; }
824 
825  unsigned uindex() const { if ( isLoc() ) return loc; return isGlob() ? glob : ( unsigned ) - 1; }
826 
827  const char * stat() const { if ( isLoc() ) return "L"; return isGlob() ? "G" : "?"; }
828  };
829 
830  void showHelp();
831 };
832 
833 
834 NCStyleDef * NCStyleDef::NCStyleDef_p = 0;
835 
836 
837 
838 void NCStyleDef::doshowset( SetType a, bool reset )
839 {
840  std::vector<Aset> aset;
841 
842  switch ( a )
843  {
844 #define PRT(T) aset.push_back( Aset( const_cast<chtype&>( attr( NCstyle::T ) ), #T ) )
845 
846  case Global:
847  PRT( AppTitle );
848  PRT( AppText );
849  break;
850 
851  case DialogBorder:
852  PRT( DialogBorder );
853  PRT( DialogTitle );
854  break;
855 
856  case DialogBorderActive:
857  PRT( DialogActiveBorder );
858  PRT( DialogActiveTitle );
859  break;
860 
861  case DialogText:
862  PRT( DialogText );
863  PRT( DialogHeadline );
864  PRT( DialogDisabled );
865  break;
866 
867  case Widget:
868  PRT( DialogPlain );
869  PRT( DialogLabel );
870  PRT( DialogData );
871  PRT( DialogHint );
872  PRT( DialogScrl );
873  break;
874 
875  case WidgetActive:
876  PRT( DialogActivePlain );
877  PRT( DialogActiveLabel );
878  PRT( DialogActiveData );
879  PRT( DialogActiveHint );
880  PRT( DialogActiveScrl );
881  break;
882 
883  case FrameWidget:
884  PRT( DialogFramePlain );
885  PRT( DialogFrameLabel );
886  PRT( DialogFrameData );
887  PRT( DialogFrameHint );
888  PRT( DialogFrameScrl );
889  break;
890 
891  case FrameWidgetActive:
892  PRT( DialogActiveFramePlain );
893  PRT( DialogActiveFrameLabel );
894  PRT( DialogActiveFrameData );
895  PRT( DialogActiveFrameHint );
896  PRT( DialogActiveFrameScrl );
897  break;
898 
899  case List:
900  PRT( ListTitle );
901  PRT( ListPlain );
902  PRT( ListLabel );
903  PRT( ListData );
904  PRT( ListHint );
905  PRT( ListSelPlain );
906  PRT( ListSelLabel );
907  PRT( ListSelData );
908  PRT( ListSelHint );
909  break;
910 
911  case ListActive:
912  PRT( ListActiveTitle );
913  PRT( ListActivePlain );
914  PRT( ListActiveLabel );
915  PRT( ListActiveData );
916  PRT( ListActiveHint );
917  PRT( ListActiveSelPlain );
918  PRT( ListActiveSelLabel );
919  PRT( ListActiveSelData );
920  PRT( ListActiveSelHint );
921  break;
922 
923  case RichText:
924  PRT( RichTextPlain );
925  PRT( RichTextTitle );
926  PRT( RichTextLink );
927  PRT( RichTextArmedlink );
928  PRT( RichTextActiveArmedlink );
929  PRT( RichTextVisitedLink );
930  PRT( RichTextB );
931  PRT( RichTextI );
932  PRT( RichTextT );
933  PRT( RichTextBI );
934  PRT( RichTextBT );
935  PRT( RichTextIT );
936  PRT( RichTextBIT );
937  break;
938 
939  case ProgressBar:
940  PRT( ProgbarCh );
941  PRT( ProgbarBgch );
942  PRT( TextCursor );
943  break;
944 
945  case MaxSetType:
946  break;
947 #undef PRT
948  }
949 
950  wChattr.set( aset, reset );
951 }
952 
953 
954 
955 void NCStyleDef::pbox( bool on )
956 {
957  p.bkgdset( A_NORMAL );
958  p.box();
959 
960  if ( on )
961  {
962  p.bkgdset( A_REVERSE );
963  p.addstr( 0, 1, "<ENTER> done " );
964  }
965  else
966  p.addstr( 0, 1, "<F5> move pad " );
967 
968  p.bkgdset( A_NORMAL );
969 }
970 
971 
972 
973 int NCStyleDef::movePad( int key )
974 {
975  pbox( true );
976  p.show();
977 
978  bool continue_bi = true;
979  int in = -1;
980 
981  do
982  {
983  refresh();
984 
985  if ( key == -1 )
986  in = getch();
987  else
988  in = key;
989 
990  switch ( in )
991  {
992  case KEY_UP:
993 
994  if ( p.begy() > 0 )
995  {
996  p.mvwin( p.begy() - 1, p.begx() );
997  }
998  break;
999 
1000  case KEY_DOWN:
1001 
1002  if ( p.begy() + p.height() < NCurses::lines() )
1003  {
1004  p.mvwin( p.begy() + 1, p.begx() );
1005  }
1006  break;
1007 
1008  case KEY_LEFT:
1009 
1010  if ( p.begx() > 0 )
1011  {
1012  p.mvwin( p.begy(), p.begx() - 1 );
1013  }
1014  break;
1015 
1016  case KEY_RIGHT:
1017 
1018  if ( p.begx() + p.width() < NCurses::cols() )
1019  {
1020  p.mvwin( p.begy(), p.begx() + 1 );
1021  }
1022  break;
1023 
1024  case -1:
1025  case KEY_ESC:
1026  case KEY_TAB:
1027  case KEY_RETURN:
1028  case KEY_F( 1 ):
1029  case KEY_F( 2 ):
1030  case KEY_F( 3 ):
1031  case KEY_F( 4 ):
1032  case KEY_F( 5 ):
1033  case KEY_F( 6 ):
1034  case KEY_F( 7 ):
1035  case KEY_F( 8 ):
1036  case KEY_F( 9 ):
1037  case KEY_F( 10 ):
1038  continue_bi = false;
1039  break;
1040  }
1041 
1042  }
1043  while ( continue_bi && key == -1 );
1044 
1045  pbox( false );
1046 
1047  if ( key != -1 )
1048  in = -1;
1049 
1050  return in;
1051 }
1052 
1053 
1054 
1055 void NCStyleDef::changeStyle()
1056 {
1057  fakestyle( wStyle.cset );
1058  p.show();
1059 
1060  bool continue_bi = true;
1061  int in = -1;
1062  int rein = 1;
1063 
1064  do
1065  {
1066  refresh();
1067 
1068  if ( rein != -2 )
1069  {
1070  in = rein;
1071  rein = -1;
1072  }
1073  else
1074  {
1075  in = getch();
1076  }
1077 
1078  switch ( in )
1079  {
1080  case KEY_F( 1 ):
1081  wStyle.handle( KEY_UP );
1082  break;
1083 
1084  case KEY_F( 2 ):
1085  wStyle.handle( KEY_DOWN );
1086  break;
1087 
1088  case KEY_F( 3 ):
1089  wSet.handle( KEY_UP );
1090  break;
1091 
1092  case KEY_F( 4 ):
1093  wSet.handle( KEY_DOWN );
1094  break;
1095 
1096  case KEY_F( 5 ):
1097  rein = movePad();
1098  break;
1099 
1100  case KEY_F( 6 ):
1101  rein = wEx.change();
1102  break;
1103 
1104  case KEY_F( 8 ):
1105  restoreStyle();
1106  break;
1107 
1108  case KEY_F( 9 ):
1109  saveStyle();
1110  break;
1111 
1112  case KEY_ESC:
1113  case KEY_F( 10 ):
1114  continue_bi = false;
1115  break;
1116 
1117  default:
1118  rein = wChattr.change();
1119  break;
1120  }
1121  }
1122  while ( continue_bi );
1123 
1124  p.hide();
1125 
1126  p.refresh();
1127 
1128  fakestyle( NCstyle::MaxStyleSet );
1129 }
1130 
1131 
1132 
1133 // query popup for ACS chars
1134 chtype NCStyleDef::queryChar( int column, chtype selbg )
1135 {
1136  std::vector<queryCharEnt> men;
1137  men.push_back( queryCharEnt( "NO CHAR", ' ' ) );
1138  men.push_back( queryCharEnt( "BLANK", ' ' ) );
1139 #define PUT(a) men.push_back( queryCharEnt( #a, a ) );
1140  PUT( ACS_CKBOARD );
1141  PUT( ACS_BOARD );
1142  PUT( ACS_BLOCK );
1143  PUT( ACS_DIAMOND );
1144  PUT( ACS_BULLET );
1145  PUT( ACS_DEGREE );
1146  PUT( ACS_PLMINUS );
1147  PUT( ACS_LEQUAL );
1148  PUT( ACS_GEQUAL );
1149  PUT( ACS_NEQUAL );
1150  PUT( ACS_S1 );
1151  PUT( ACS_S3 );
1152  PUT( ACS_S7 );
1153  PUT( ACS_S9 );
1154  PUT( ACS_PI );
1155  PUT( ACS_LANTERN );
1156  PUT( ACS_STERLING );
1157  PUT( ACS_LARROW );
1158  PUT( ACS_RARROW );
1159  PUT( ACS_DARROW );
1160  PUT( ACS_UARROW );
1161  PUT( ACS_ULCORNER );
1162  PUT( ACS_URCORNER );
1163  PUT( ACS_LLCORNER );
1164  PUT( ACS_LRCORNER );
1165  PUT( ACS_VLINE );
1166  PUT( ACS_LTEE );
1167  PUT( ACS_RTEE );
1168  PUT( ACS_BTEE );
1169  PUT( ACS_TTEE );
1170  PUT( ACS_HLINE );
1171  PUT( ACS_PLUS );
1172 #undef PUT
1173 
1174  chtype defbg = A_NORMAL;
1175  unsigned lrow = men.size() - men.size() / 2;
1176 
1177  NCursesPanel popup( lrow + 2, 39, 1, 1 );
1178  popup.bkgd( defbg );
1179  popup.box();
1180 
1181  popup.show();
1182  chtype ret = ( chtype ) - 1;
1183  unsigned idx = 0;
1184  int in = -1;
1185 
1186  do
1187  {
1188  int l = 1;
1189  int c = 1;
1190  int len = 13;
1191 
1192  for ( unsigned i = 0; i < men.size(); ++i, ++l )
1193  {
1194  if ( i == lrow )
1195  {
1196  c += len + 6;
1197  l = 1;
1198  }
1199 
1200  popup.bkgdset( defbg );
1201 
1202  popup.addstr( l, c, ( i == idx ? "->" : " " ) );
1203  popup.bkgdset( i == idx ? selbg : defbg );
1204  popup.addch( ' ' );
1205  popup.addch( men[i].c );
1206  popup.printw( " %-*.*s", len, len, men[i].l.c_str() );
1207  }
1208 
1209  popup.refresh();
1210 
1211  switch ( ( in = getch() ) )
1212  {
1213 
1214  case KEY_UP:
1215 
1216  if ( idx )
1217  --idx;
1218  break;
1219 
1220  case KEY_DOWN:
1221 
1222  if ( idx + 1 < men.size() )
1223  ++idx;
1224  break;
1225 
1226  case KEY_RETURN:
1227  ret = idx ? men[idx].c : 0;
1228 
1229  case KEY_ESC:
1230  in = -1;
1231 
1232  break;
1233  }
1234  }
1235  while ( in != -1 );
1236 
1237  popup.hide();
1238  popup.refresh();
1239 
1240  return ret;
1241 }
1242 
1243 
1244 #define BGSET(a) W.bkgdset( st.a )
1245 
1246 static int hi = 4;
1247 static int wi = 15;
1248 
1249 
1250 inline void frame( NCursesWindow & w, int l, int c, int H = 0, int W = 0 )
1251 {
1252  if ( !H )
1253  H = hi;
1254 
1255  if ( !W )
1256  W = wi;
1257 
1258  w.vline( l, c, H );
1259  w.vline( l, c + W, H );
1260  w.hline( l, c, W );
1261  w.hline( l + H, c, W );
1262 
1263  w.addch( l, c, ACS_ULCORNER );
1264  w.addch( l + H, c, ACS_LLCORNER );
1265  w.addch( l, c + W, ACS_URCORNER );
1266  w.addch( l + H, c + W, ACS_LRCORNER );
1267 }
1268 
1269 
1270 inline void laex( NCursesWindow & W, const char * T, NCstyle::StItem st )
1271 {
1272  BGSET( hint );
1273  W.addch( *T );
1274  BGSET( label );
1275  W.addstr( T + 1 );
1276 }
1277 
1278 
1279 inline void itex( NCursesWindow & W, const char * T, NCstyle::StItem st )
1280 {
1281  BGSET( plain );
1282  W.addstr( "(" );
1283  BGSET( data );
1284  W.addstr( "X" );
1285  BGSET( plain );
1286  W.addstr( ") " );
1287  laex( W, T, st );
1288 }
1289 
1290 
1291 inline void butex( NCursesWindow & W, int L, int C, const char * T, NCstyle::StWidget st )
1292 {
1293  W.move( L, C );
1294  itex( W, T, st );
1295  BGSET( scrl );
1296  W.addch( ACS_DARROW );
1297 }
1298 
1299 
1300 inline void frameex( NCursesWindow & W, int L, int C, const char * T, NCstyle::StWidget st )
1301 {
1302  BGSET( plain );
1303  frame( W, L, C );
1304  W.move( L, C + 1 );
1305  laex( W, T, st );
1306  BGSET( scrl );
1307  W.addch( L + hi, C + 1, ACS_LTEE );
1308  W.addch( ACS_HLINE );
1309  W.addch( ACS_RTEE );
1310  W.addch( L + 1, C + wi, ACS_TTEE );
1311  W.addch( L + 2, C + wi, ACS_BTEE );
1312 }
1313 
1314 
1315 inline void listex( NCursesWindow & W, int L, int C, NCstyle::StList st )
1316 {
1317  BGSET( title );
1318  W.printw( L, C, "%-*s", wi - 1, "Title" );
1319  ++L;
1320  BGSET( item.plain );
1321  W.printw( L, C, "%-*s", wi - 1, "" );
1322  W.move( L, C );
1323  itex( W, "Item", st.item );
1324  ++L;
1325  BGSET( selected.plain );
1326  W.printw( L, C, "%-*s", wi - 1, "" );
1327  W.move( L, C );
1328  itex( W, "Selected", st.selected );
1329 }
1330 
1331 
1332 inline void widex( NCursesWindow & W, int L, int C, const char * T,
1334 {
1335  butex( W, L, C, T, w );
1336  L += 2;
1337  frameex( W, L, C, T, f );
1338  L += 1;
1339  listex( W, L, C + 1, l );
1340 }
1341 
1342 
1343 
1344 void NCStyleDef::showex( ExMode mode )
1345 {
1346  static NCursesPanel W( 14, NCurses::cols(), 0, 0 );
1347 
1348  if ( mode == EX_TOGGLE )
1349  mode = W.hidden() ? EX_ON : EX_OFF;
1350 
1351  if ( mode == EX_OFF )
1352  {
1353  if ( !W.hidden() )
1354  {
1355  W.hide();
1356  W.refresh();
1357  }
1358 
1359  return;
1360  }
1361 
1362  if ( mode == EX_ON && W.hidden() )
1363  {
1364  W.show();
1365  }
1366 
1367  if ( W.hidden() )
1368  return;
1369 
1370  const NCstyle::Style & st( NCStyleDef_p->NCstyle_C.getStyle( NCStyleDef_p->NCstyle_C.fakestyle_e ) );
1371 
1372  BGSET( dumb.text );
1373  W.clear();
1374  BGSET( border.text );
1375  W.box();
1376  BGSET( border.title );
1377  W.addstr( 0, 1, "normal dialog" );
1378  int l = 1;
1379  int c = 1;
1380  BGSET( activeBorder.text );
1381  frame( W, l, c, W.height() - 2, W.width() - 2 );
1382  BGSET( activeBorder.title );
1383  W.addstr( l, c + 1, "active dialog" );
1384  l = 3;
1385  c = 3;
1386  BGSET( dumb.title );
1387  W.addstr( l, c, "Heading" );
1388  BGSET( dumb.text );
1389  frame( W, l + 2, c );
1390  W.addstr( l + 2, c + 1, "Frame" );
1391  W.addstr( l + 4, c + 1, "Some text" );
1392  c += 20;
1393  widex( W, l, c, "Disabled", st.disabled, st.disabled, st.disabledList );
1394  c += 20;
1395  widex( W, l, c, "Normal", st.normal, st.frame, st.list );
1396  c += 20;
1397  widex( W, l, c, "Active", st.active, st.activeFrame, st.activeList );
1398  l += hi + 4;
1399  c = 3;
1400  BGSET( progbar.bar.chattr );
1401  W.addstr( l, c, " " );
1402  BGSET( progbar.bar.getNonChar() );
1403  W.addstr( "50" );
1404  BGSET( progbar.nonbar.getNonChar() );
1405  W.addstr( "%" );
1406  BGSET( progbar.nonbar.chattr );
1407  W.addstr( " " );
1408  W.refresh();
1409 }
1410 
1411 
1412 void NCStyleDef::saveStyle()
1413 {
1414  std::string fname( "NCstyle." + NCstyle_C.styleName + ".h" );
1415  std::string hname( "NCstyle_" + NCstyle_C.styleName + "_h" );
1416  std::string fpath( "/tmp/" );
1417  fpath += fname;
1418 
1419  std::ofstream out( fpath.c_str(), std::ios::out );
1420  NCursesPanel p( 5, NCurses::cols() - 4, ( NCurses::lines() - 5 ) / 2, 2 );
1421  int pl = p.height() / 2;
1422  p.box();
1423 
1424  if ( !out.good() )
1425  {
1426  p.bkgd( NCattribute::color_pair( COLOR_WHITE, COLOR_RED ) );
1427  p.printw( pl, 2, "Can't open output file \"%s\"!", fpath.c_str() );
1428  p.show();
1429  p.refresh();
1430  getch();
1431  p.hide();
1432  p.refresh();
1433  return;
1434  }
1435 
1436  p.bkgd( NCattribute::color_pair( COLOR_CYAN, COLOR_BLACK ) );
1437 
1438  p.printw( pl, 2, "Saving style \"%s\" in \"%s\" ...", NCstyle_C.styleName.c_str(), fpath.c_str() );
1439  p.show();
1440  p.refresh();
1441 
1442  out << "/*" << std::endl;
1443  out << " Copyright (C) 2000-2012 Novell, Inc" << std::endl;
1444  out << " This library is free software; you can redistribute it and/or modify" << std::endl;
1445  out << " it under the terms of the GNU Lesser General Public License as" << std::endl;
1446  out << " published by the Free Software Foundation; either version 2.1 of the" << std::endl;
1447  out << " License, or (at your option) version 3.0 of the License. This library" << std::endl;
1448  out << " is distributed in the hope that it will be useful, but WITHOUT ANY" << std::endl;
1449  out << " WARRANTY; without even the implied warranty of MERCHANTABILITY or" << std::endl;
1450  out << " FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public" << std::endl;
1451  out << " License for more details. You should have received a copy of the GNU" << std::endl;
1452  out << " Lesser General Public License along with this library; if not, write" << std::endl;
1453  out << " to the Free Software Foundation, Inc., 51 Franklin Street, Fifth" << std::endl;
1454  out << " Floor, Boston, MA 02110-1301 USA" << std::endl;
1455  out << "*/" << std::endl;
1456  out << std::endl;
1457  out << std::endl;
1458  out << "/*-/" << std::endl;
1459  out << std::endl;
1460  out << " File: " << fname << std::endl;
1461  out << std::endl;
1462  out << " Author: Generated by class NCstyle" << std::endl;
1463  out << std::endl;
1464  out << "/-*/" << std::endl;
1465  out << "#ifndef " << hname << std::endl;
1466  out << "#define " << hname << std::endl;
1467  out << "" << std::endl;
1468  out << "#include \"NCstyle.h\"" << std::endl;
1469  out << "" << std::endl;
1470  out << "inline void NCstyleInit_" << NCstyle_C.styleName << "( std::vector<NCstyle::Style> & styleSet )" << std::endl;
1471  out << "{" << std::endl;
1472 
1473  out << " //=================================================================" << std::endl;
1474  out << " // init global attributes" << std::endl;
1475  out << " //=================================================================" << std::endl;
1476  out << " NCattrset * attrset( &styleSet[NCstyle::" << NCstyle::dumpName( NCstyle::DefaultStyle ) << "].getAttrGlobal() );" << std::endl;
1477 
1478  for ( NCstyle::STglobal a = ( NCstyle::STglobal )0; a < NCstyle::MaxSTglobal; a = ( NCstyle::STglobal )( a + 1 ) )
1479  {
1480  out << " attrset->setAttr( NCstyle::"
1481  << NCstyle::dumpName( a )
1482  << ", ";
1483  dumpChtype( out, NCstyle_C( a ) )
1484  << " );" << std::endl;
1485  }
1486 
1487  out << " //=================================================================" << std::endl;
1488  out << " // init local attributes" << std::endl;
1489  out << " //=================================================================" << std::endl;
1490 
1491  for ( NCstyle::StyleSet sts = ( NCstyle::StyleSet )0; sts < NCstyle::MaxStyleSet; sts = ( NCstyle::StyleSet )( sts + 1 ) )
1492  {
1493  out << " // " << NCstyle::dumpName( sts ) << std::endl;
1494  out << " attrset = &styleSet[NCstyle::" << NCstyle::dumpName( sts ) << "].getAttrLocal();" << std::endl;
1495 
1496  for ( NCstyle::STlocal a = ( NCstyle::STlocal )0; a < NCstyle::MaxSTlocal; a = ( NCstyle::STlocal )( a + 1 ) )
1497  {
1498  out << " attrset->setAttr( NCstyle::"
1499  << NCstyle::dumpName( a )
1500  << ", ";
1501  dumpChtype( out, NCstyle_C.styleSet[sts]( a ) )
1502  << " );" << std::endl;
1503  }
1504  }
1505 
1506  out << "}" << std::endl;
1507  out << "#endif // " << hname << std::endl;
1508  out.close();
1509 
1510  if ( ! out.good() )
1511  {
1512  p.bkgd( NCattribute::color_pair( COLOR_WHITE, COLOR_RED ) );
1513  p.printw( " FAILED!" );
1514  }
1515  else
1516  {
1517  p.printw( " DONE!" );
1518 
1519  }
1520 
1521  p.show();
1522 
1523  p.refresh();
1524  getch();
1525  p.hide();
1526  p.refresh();
1527 }
1528 
1529 
1530 void NCStyleDef::restoreStyle()
1531 {
1532  std::string fname( "NCstyle." + NCstyle_C.styleName + ".h" );
1533  std::string fpath( "/tmp/" );
1534  fpath += fname;
1535 
1536  std::ifstream inp( fpath.c_str(), std::ios::in );
1537  int ph = 5;
1538  NCursesPanel p( ph, NCurses::cols() - 4, ( NCurses::lines() - ph ) / 2, 2 );
1539  int pl = 2;
1540  p.box();
1541 
1542  if ( !inp.good() )
1543  {
1544  p.bkgd( NCattribute::color_pair( COLOR_WHITE, COLOR_RED ) );
1545  p.printw( pl, 2, "Can't open input file \"%s\"!", fpath.c_str() );
1546  p.show();
1547  p.refresh();
1548  getch();
1549  p.hide();
1550  p.refresh();
1551  return;
1552  }
1553 
1554  p.bkgd( NCattribute::color_pair( COLOR_CYAN, COLOR_BLACK ) );
1555 
1556  p.printw( pl, 2, "Reding style \"%s\" from \"%s\" ...", NCstyle_C.styleName.c_str(), fpath.c_str() );
1557  p.show();
1558  p.refresh();
1559 
1560  std::list<std::string> data_vec[NCstyle::MaxStyleSet+1];
1561  NCstyle::StyleSet cvec = NCstyle::MaxStyleSet;
1562 
1563  std::string initfnc_ti( "inline void NCstyleInit_" );
1564  initfnc_ti += NCstyle_C.styleName + "(";
1565  std::string attrdef( " attrset->setAttr( NCstyle::" );
1566  std::string stydef( " attrset = &styleSet[NCstyle::" );
1567 
1568  enum STATE { PRE, ONFNC, IN, POST, ERROR };
1569  STATE psaw = PRE;
1570 
1571  std::string line( "" );
1572  unsigned lineno = 0;
1573 
1574  while ( inp.good() && psaw != POST && psaw != ERROR )
1575  {
1576  char c;
1577  line = "";
1578 
1579  while ( inp.get( c ), inp.good() && c != '\n' )
1580  line += c;
1581 
1582  {
1583  ++lineno;
1584  // consume
1585 
1586  switch ( psaw )
1587  {
1588  case PRE:
1589 
1590  if ( line.find( initfnc_ti ) == 0 )
1591  psaw = ONFNC;
1592 
1593  break;
1594 
1595  case ONFNC:
1596  if ( line == "{" || line.find( " //" ) == 0 )
1597  break;
1598 
1599  if ( line == " NCattrset * attrset( &styleSet[NCstyle::DefaultStyle].getAttrGlobal() );" )
1600  {
1601  psaw = IN;
1602  cvec = NCstyle::MaxStyleSet;
1603  //p.printw( "[GLOBAL]" );
1604  //p.show();
1605  //p.refresh();
1606  }
1607  else
1608  psaw = ERROR;
1609 
1610  break;
1611 
1612  case IN:
1613  if ( line == "}" )
1614  {
1615  psaw = POST;
1616  break;
1617  }
1618 
1619  if ( line.find( " //" ) == 0 )
1620  break;
1621 
1622  if ( line.find( attrdef ) == 0 )
1623  {
1624  data_vec[cvec].push_back( line.substr( attrdef.size() ) );
1625  //p.printw( "." );
1626  }
1627  else if ( line.find( stydef ) == 0 )
1628  {
1629  line.erase( 0, stydef.size() );
1630 
1631  if ( line.find( "DefaultStyle]" ) == 0 )
1632  {
1633  cvec = NCstyle::DefaultStyle;
1634  //p.printw( "[DefaultStyle]" );
1635  }
1636  else if ( line.find( "InfoStyle]" ) == 0 )
1637  {
1638  cvec = NCstyle::InfoStyle;
1639  //p.printw( "[InfoStyle]" );
1640  }
1641  else if ( line.find( "WarnStyle]" ) == 0 )
1642  {
1643  cvec = NCstyle::WarnStyle;
1644  //p.printw( "[WarnStyle]" );
1645  }
1646  else if ( line.find( "PopupStyle]" ) == 0 )
1647  {
1648  cvec = NCstyle::PopupStyle;
1649  //p.printw( "[PopupStyle]" );
1650  }
1651  else
1652  {
1653  psaw = ERROR;
1654  }
1655 
1656  p.show();
1657 
1658  p.refresh();
1659  }
1660  else
1661  {
1662  psaw = ERROR;
1663  }
1664 
1665  break;
1666 
1667  case ERROR:
1668 
1669  case POST:
1670  break;
1671  }
1672  }
1673  }
1674 
1675  if ( psaw != POST )
1676  {
1677  p.bkgd( NCattribute::color_pair( COLOR_WHITE, COLOR_RED ) );
1678  p.printw( " FAILED stage %d!\n[%d]>>%s<<", psaw, lineno, line.c_str() );
1679  p.show();
1680  p.refresh();
1681  getch();
1682  p.hide();
1683  p.refresh();
1684  return;
1685  }
1686 
1687  inp.close();
1688 
1689  // parse data
1690 
1691  std::vector<NCattrset> attr_vec;
1692 
1693  for ( cvec = ( NCstyle::StyleSet )0; cvec <= NCstyle::MaxStyleSet; cvec = ( NCstyle::StyleSet )( cvec + 1 ) )
1694  {
1695  attr_vec.push_back( cvec == NCstyle::MaxStyleSet ? NCattrset( NCstyle::MaxSTglobal ) : NCattrset( NCstyle::MaxSTlocal ) );
1696  }
1697 
1698  std::map<std::string, lookupIdx> lookupmap;
1699 
1700  for ( NCstyle::STglobal a = ( NCstyle::STglobal )0; a < NCstyle::MaxSTglobal; a = ( NCstyle::STglobal )( a + 1 ) )
1701  {
1702  std::map<std::string, lookupIdx>::value_type v( NCstyle::dumpName( a ), lookupIdx( a ) );
1703  lookupmap.insert( v );
1704  }
1705 
1706  for ( NCstyle::STlocal a = ( NCstyle::STlocal )0; a < NCstyle::MaxSTlocal; a = ( NCstyle::STlocal )( a + 1 ) )
1707  {
1708  std::map<std::string, lookupIdx>::value_type v( NCstyle::dumpName( a ), lookupIdx( a ) );
1709  lookupmap.insert( v );
1710  }
1711 
1712  //p.printw( "\n[PARSE]" );
1713  //p.show();
1714  //p.refresh();
1715 
1716  // globals first
1717  for ( cvec = ( NCstyle::StyleSet )( NCstyle::MaxStyleSet + 1 ); cvec > 0; )
1718  {
1719  cvec = ( NCstyle::StyleSet )( cvec - 1 );
1720  //p.printw( "[%s]", NCstyle::dumpName( cvec ).c_str() );
1721  //p.show();
1722  //p.refresh();
1723 
1724  for ( std::list<std::string>::iterator i = data_vec[cvec].begin(); i != data_vec[cvec].end(); ++i )
1725  {
1726  std::string::size_type sep = i->find( ", " );
1727 
1728  if ( sep != std::string::npos )
1729  {
1730  std::string id( i->substr( 0, sep ) );
1731  std::string val( i->substr( sep + 2 ) );
1732  sep = val.find( " " );
1733 
1734  if ( sep != std::string::npos )
1735  {
1736  val.erase( sep );
1737  }
1738 
1739  std::map<std::string, lookupIdx>::const_iterator ldat = lookupmap.find( id );
1740 
1741  if ( ldat == lookupmap.end() || ldat->second.isUnknown() )
1742  {
1743  p.printw( "{UNKNOWN:%s=%s}", id.c_str(), val.c_str() );
1744  p.show();
1745  p.refresh();
1746  }
1747  else
1748  {
1749  chtype ch = atoi( val.c_str() );
1750  sep = val.find( "|" );
1751 
1752  if ( sep != std::string::npos )
1753  {
1754  val.erase( 0, sep + 1 );
1755 
1756  while ( val.size() )
1757  {
1758  sep = val.find( "|" );
1759  std::string tt = val.substr( 0, sep );
1760 #define IFASSIGN(T) if ( tt == #T ) ch |= T
1761  IFASSIGN( A_STANDOUT );
1762  else IFASSIGN( A_UNDERLINE );
1763  else IFASSIGN( A_REVERSE );
1764  else IFASSIGN( A_BLINK );
1765  else IFASSIGN( A_DIM );
1766  else IFASSIGN( A_BOLD );
1767  else IFASSIGN( A_INVIS );
1768 
1769 #undef IFASSIGN
1770  val.erase( 0, ( sep != std::string::npos ) ? sep + 1 : sep );
1771  }
1772  }
1773 
1774  // ready to assign
1775  if ( ldat->second.isLoc() )
1776  {
1777  // actual value is local
1778  if ( cvec == NCstyle::MaxStyleSet )
1779  {
1780  // global data parsed
1781  for ( unsigned ii = 0; ii < NCstyle::MaxStyleSet; ++ii )
1782  {
1783  attr_vec[ii].setAttr( ldat->second.uindex(), ch );
1784  }
1785  }
1786  else
1787  {
1788  // local data parsed
1789  attr_vec[cvec].setAttr( ldat->second.uindex(), ch );
1790  }
1791 
1792  attr_vec[cvec].setAttr( ldat->second.uindex(), ch );
1793  }
1794  else if ( ldat->second.isGlob() )
1795  {
1796  // actual value is global
1797  attr_vec[NCstyle::MaxStyleSet].setAttr( ldat->second.uindex(), ch );
1798  }
1799  }
1800 
1801  //p.printw( "." );
1802  //p.show();
1803  //p.refresh();
1804  }
1805  else
1806  {
1807  p.printw( "{NOVAL:%s}", i->c_str() );
1808  p.show();
1809  p.refresh();
1810  }
1811  }
1812  }
1813 
1814  // apply
1815  cvec = ( NCstyle::StyleSet )0;
1816 
1817  NCstyle_C.getStyle( cvec ).getAttrGlobal() = attr_vec[NCstyle::MaxStyleSet];
1818 
1819  for ( ; cvec < NCstyle::MaxStyleSet; cvec = ( NCstyle::StyleSet )( cvec + 1 ) )
1820  {
1821  NCstyle_C.getStyle( cvec ).getAttrLocal() = attr_vec[cvec];
1822  }
1823 
1824  attrchanged();
1825 
1826  // finish
1827  p.printw( " DONE!" );
1828  p.show();
1829  p.refresh();
1830  getch();
1831  p.hide();
1832  p.refresh();
1833 }
1834 
1835 
1836 void NCDefineStyle( NCstyle & style )
1837 {
1838  static NCStyleDef cstyle( style );
1839  cstyle.changeStyle();
1840 }
C++ class for windows.
Definition: ncursesw.h:904
int printw(const char *fmt,...)
Definition: ncursesw.cc:75
void syncup()
Definition: ncursesw.h:1656
int vline(int len, chtype ch=0)
Definition: ncursesw.h:1499
int bkgd(const chtype ch)
Definition: ncursesw.h:1443
virtual int refresh()
Definition: ncursesp.cc:112
void bkgdset(chtype ch)
Definition: ncursesw.h:1448
void show()
Definition: ncursesp.h:162
int mvwin(int y, int x)
Definition: ncursesp.h:191
virtual int refresh()
Definition: ncursesw.h:1708
int hline(int len, chtype ch=0)
Definition: ncursesw.h:1485
int height() const
Definition: ncursesw.h:1070
int addch(const char ch)
Definition: ncursesw.h:1228
void hide()
Definition: ncursesp.h:150
int begy() const
Definition: ncursesw.h:1085
int begx() const
Definition: ncursesw.h:1080
int move(int y, int x)
Definition: ncursesw.h:1155
int addstr(const char *str, int n=-1)
Definition: ncursesw.h:1276
int width() const
Definition: ncursesw.h:1075