libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCstyle.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019    File:       NCstyle.cc
00020 
00021    Author:     Michael Andres <ma@suse.de>
00022 
00023 /-*/
00024 
00025 #include <fstream>
00026 #include "fnmatch.h"
00027 
00028 #define  YUILogComponent "ncurses"
00029 #include <yui/YUILog.h>
00030 #include "NCurses.h"
00031 #include "NCStyleDef.h"
00032 
00033 #include "NCstyle.mono.h"
00034 #include "NCstyle.braille.h"
00035 #include "NCstyle.linux.h"
00036 #include "NCstyle.xterm.h"
00037 #include "NCstyle.rxvt.h"
00038 #include "NCstyle.highcontrast.h"
00039 #include "NCstyle.inverted.h"
00040 
00041 //initialize number of colors and color pairs
00042 int NCattribute::_colors = ::COLORS;
00043 int NCattribute::_pairs = ::COLOR_PAIRS;
00044 
00045 
00046 
00047 unsigned NCstyle::Style::sanitycheck()
00048 {
00049     return MaxSTglobal;
00050 }
00051 
00052 NCattrset NCstyle::Style::attrGlobal( sanitycheck() );
00053 
00054 
00055 
00056 // Initialize subclass StDialog in Style constructor
00057 //                    (esp. copy constructor). Default copy constructor
00058 //                    is not appropriate, because StDialog contains
00059 //                    references to subclass NCattrset.
00060 NCstyle::StDialog NCstyle::Style::initDialog()
00061 {
00062     return StDialog( StBase( attr( DialogTitle ),
00063                              attr( DialogBorder ) ),
00064                      StBase( attr( DialogActiveTitle ),
00065                              attr( DialogActiveBorder ) ),
00066                      StBase( attr( DialogHeadline ),
00067                              attr( DialogText ) ),
00068                      StWidget( attr( DialogDisabled ),
00069                                attr( DialogDisabled ),
00070                                attr( DialogDisabled ),
00071                                attr( DialogDisabled ),
00072                                attr( DialogDisabled ) ),
00073                      StWidget( attr( DialogPlain ),
00074                                attr( DialogLabel ),
00075                                attr( DialogData ),
00076                                attr( DialogHint ),
00077                                attr( DialogScrl ) ),
00078                      StWidget( attr( DialogActivePlain ),
00079                                attr( DialogActiveLabel ),
00080                                attr( DialogActiveData ),
00081                                attr( DialogActiveHint ),
00082                                attr( DialogActiveScrl ) ),
00083                      StWidget( attr( DialogFramePlain ),
00084                                attr( DialogFrameLabel ),
00085                                attr( DialogFrameData ),
00086                                attr( DialogFrameHint ),
00087                                attr( DialogFrameScrl ) ),
00088                      StWidget( attr( DialogActiveFramePlain ),
00089                                attr( DialogActiveFrameLabel ),
00090                                attr( DialogActiveFrameData ),
00091                                attr( DialogActiveFrameHint ),
00092                                attr( DialogActiveFrameScrl ) ),
00093                      StList( attr( ListTitle ),
00094                              StItem( attr( ListPlain ),
00095                                      attr( ListLabel ),
00096                                      attr( ListData ),
00097                                      attr( ListHint ) ),
00098                              StItem( attr( ListSelPlain ),
00099                                      attr( ListSelLabel ),
00100                                      attr( ListSelData ),
00101                                      attr( ListSelHint ) ) ),
00102                      StList( attr( ListActiveTitle ),
00103                              StItem( attr( ListActivePlain ),
00104                                      attr( ListActiveLabel ),
00105                                      attr( ListActiveData ),
00106                                      attr( ListActiveHint ) ),
00107                              StItem( attr( ListActiveSelPlain ),
00108                                      attr( ListActiveSelLabel ),
00109                                      attr( ListActiveSelData ),
00110                                      attr( ListActiveSelHint ) ) ),
00111                      StList( attr( DialogDisabled ),
00112                              StItem( attr( DialogDisabled ),
00113                                      attr( DialogDisabled ),
00114                                      attr( DialogDisabled ),
00115                                      attr( DialogDisabled ) ),
00116                              StItem( attr( DialogDisabled ),
00117                                      attr( DialogDisabled ),
00118                                      attr( DialogDisabled ),
00119                                      attr( DialogDisabled ) ) ),
00120                      StProgbar( attr( ProgbarCh ),
00121                                 attr( ProgbarBgch ) ),
00122                      StRichtext( attr( RichTextPlain ),
00123                                  attr( RichTextTitle ),
00124                                  attr( RichTextLink ),
00125                                  attr( RichTextArmedlink ),
00126                                  attr( RichTextActiveArmedlink ),
00127                                  attr( RichTextVisitedLink ),
00128                                  attr( RichTextB ),
00129                                  attr( RichTextI ),
00130                                  attr( RichTextT ),
00131                                  attr( RichTextBI ),
00132                                  attr( RichTextBT ),
00133                                  attr( RichTextIT ),
00134                                  attr( RichTextBIT ) ),
00135                      attr( TextCursor )
00136                    );
00137 }
00138 
00139 
00140 
00141 NCstyle::Style::Style()
00142         : NCattrset( MaxSTlocal )
00143         , StDialog( initDialog() )
00144 {}
00145 
00146 
00147 
00148 NCstyle::Style::Style( const Style & rhs )
00149         : NCattrset( rhs )
00150         , StDialog( initDialog() )
00151 {}
00152 
00153 
00154 
00155 NCstyle::Style::~Style()
00156 {}
00157 
00158 
00159 
00160 
00161 
00162 #define PRT(t) case NCstyle::t: return #t;
00163 
00164 std::string NCstyle::dumpName( NCstyle::StyleSet a )
00165 {
00166     switch ( a )
00167     {
00168         PRT( DefaultStyle );
00169         PRT( InfoStyle );
00170         PRT( WarnStyle );
00171         PRT( PopupStyle );
00172 
00173         case NCstyle::MaxStyleSet:
00174             break;
00175     }
00176 
00177     return "unknown";
00178 }
00179 
00180 std::string NCstyle::dumpName( NCstyle::STglobal a )
00181 {
00182     switch ( a )
00183     {
00184         PRT( AppTitle );
00185         PRT( AppText );
00186 
00187         case NCstyle::MaxSTglobal:
00188             break;
00189     }
00190 
00191     return "unknown";
00192 }
00193 
00194 std::string NCstyle::dumpName( NCstyle::STlocal a )
00195 {
00196     switch ( a )
00197     {
00198         PRT( DialogBorder );
00199         PRT( DialogTitle );
00200         PRT( DialogActiveBorder );
00201         PRT( DialogActiveTitle );
00202         //
00203         PRT( DialogText );
00204         PRT( DialogHeadline );
00205         //
00206         PRT( DialogDisabled );
00207         //
00208         PRT( DialogPlain );
00209         PRT( DialogLabel );
00210         PRT( DialogData );
00211         PRT( DialogHint );
00212         PRT( DialogScrl );
00213         PRT( DialogActivePlain );
00214         PRT( DialogActiveLabel );
00215         PRT( DialogActiveData );
00216         PRT( DialogActiveHint );
00217         PRT( DialogActiveScrl );
00218         //
00219         PRT( DialogFramePlain );
00220         PRT( DialogFrameLabel );
00221         PRT( DialogFrameData );
00222         PRT( DialogFrameHint );
00223         PRT( DialogFrameScrl );
00224         PRT( DialogActiveFramePlain );
00225         PRT( DialogActiveFrameLabel );
00226         PRT( DialogActiveFrameData );
00227         PRT( DialogActiveFrameHint );
00228         PRT( DialogActiveFrameScrl );
00229         //
00230         PRT( ListTitle );
00231         PRT( ListPlain );
00232         PRT( ListLabel );
00233         PRT( ListData );
00234         PRT( ListHint );
00235         PRT( ListSelPlain );
00236         PRT( ListSelLabel );
00237         PRT( ListSelData );
00238         PRT( ListSelHint );
00239         //
00240         PRT( ListActiveTitle );
00241         PRT( ListActivePlain );
00242         PRT( ListActiveLabel );
00243         PRT( ListActiveData );
00244         PRT( ListActiveHint );
00245         PRT( ListActiveSelPlain );
00246         PRT( ListActiveSelLabel );
00247         PRT( ListActiveSelData );
00248         PRT( ListActiveSelHint );
00249         //
00250         PRT( RichTextPlain );
00251         PRT( RichTextTitle );
00252         PRT( RichTextLink );
00253         PRT( RichTextArmedlink );
00254         PRT( RichTextActiveArmedlink );
00255         PRT( RichTextVisitedLink );
00256         PRT( RichTextB );
00257         PRT( RichTextI );
00258         PRT( RichTextT );
00259         PRT( RichTextBI );
00260         PRT( RichTextBT );
00261         PRT( RichTextIT );
00262         PRT( RichTextBIT );
00263         //
00264         PRT( ProgbarCh );
00265         PRT( ProgbarBgch );
00266         //
00267         PRT( TextCursor );
00268 
00269         case NCstyle::MaxSTlocal:
00270             break;
00271     }
00272 
00273     return "unknown";
00274 }
00275 
00276 #undef PRT
00277 
00278 
00279 
00280 NCstyle::NCstyle( std::string term_t )
00281     : styleName( "linux" )
00282     , term( term_t )
00283     , styleSet( MaxStyleSet )
00284     , fakestyle_e( MaxStyleSet )
00285 {
00286     char *user_defined_style = getenv( "Y2NCURSES_COLOR_THEME" );
00287 
00288     if ( user_defined_style && *user_defined_style )
00289     {
00290         styleName = user_defined_style;
00291         yuiMilestone() << "User-defined style found: " << styleName.c_str() << std::endl;
00292     }
00293     else
00294     {
00295         if ( NCattribute::colors() )
00296         {
00297             if ( getenv( "Y2_BRAILLE" ) != NULL )
00298             {
00299                 styleName = "braille";
00300             }
00301             else
00302             {
00303                 if ( ! fnmatch( "xterm*", term_t.c_str(), 0 ) )
00304                     styleName = "xterm";
00305                 else if ( ! fnmatch( "rxvt*", term_t.c_str(), 0 ) )
00306                     styleName = "rxvt";
00307             }
00308         }
00309         else
00310         {
00311             styleName = "mono";
00312         }
00313     }
00314 
00315     yuiMilestone() << "Init " << term_t << " using " << ( NCattribute::colors() ? "color" : "bw" )
00316 
00317                    << " => " << MaxStyleSet << " styles in " << styleName << std::endl;
00318 
00319 #define IF_STYLE_INIT(n) if ( styleName == #n ) { NCstyleInit_##n( styleSet ); }
00320     IF_STYLE_INIT( linux )
00321         else IF_STYLE_INIT( xterm )
00322             else IF_STYLE_INIT( rxvt )
00323                 else IF_STYLE_INIT( mono )
00324                     else IF_STYLE_INIT( braille )
00325                         else IF_STYLE_INIT( highcontrast )
00326                             else IF_STYLE_INIT( inverted )
00327                                 else NCstyleInit_linux( styleSet );
00328 }
00329 
00330 
00331 
00332 NCstyle::~NCstyle()
00333 {
00334 }
00335 
00336 
00337 
00338 void NCstyle::nextStyle()
00339 {
00340     if ( !NCattribute::colors() ) return;
00341 
00342     if ( styleName == "mono" )
00343     {
00344         if ( term == "xterm" )
00345         {
00346             styleName = "xterm";
00347             NCstyleInit_xterm( styleSet );
00348         }
00349         else if ( term == "rxvt" )
00350         {
00351             styleName = "rxvt";
00352             NCstyleInit_rxvt( styleSet );
00353         }
00354         else
00355         {
00356             styleName = "linux";
00357             NCstyleInit_linux( styleSet );
00358         }
00359     }
00360     else if ( styleName == "braille" )
00361     {
00362         styleName = "mono";
00363         NCstyleInit_mono( styleSet );
00364     }
00365     else
00366     {
00367         styleName = "braille";
00368         NCstyleInit_braille( styleSet );
00369     }
00370 }
00371 
00372 
00373 
00374 void NCstyle::changeSyle()
00375 {
00376     NCDefineStyle( *this );
00377 }
00378 
00379 
00380 
00381 void NCstyle::fakestyle( StyleSet f )
00382 {
00383     fakestyle_e = f;
00384     NCurses::Redraw();
00385 }
 All Classes Functions Variables