libyui-ncurses  2.44.1
 All Classes Functions Variables
NCstyle.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: NCstyle.cc
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #include <fstream>
26 #include "fnmatch.h"
27 
28 #define YUILogComponent "ncurses"
29 #include <yui/YUILog.h>
30 #include "NCurses.h"
31 #include "NCStyleDef.h"
32 
33 #include "NCstyle.mono.h"
34 #include "NCstyle.braille.h"
35 #include "NCstyle.linux.h"
36 #include "NCstyle.xterm.h"
37 #include "NCstyle.rxvt.h"
38 #include "NCstyle.highcontrast.h"
39 #include "NCstyle.inverted.h"
40 
41 //initialize number of colors and color pairs
42 int NCattribute::_colors = ::COLORS;
43 int NCattribute::_pairs = ::COLOR_PAIRS;
44 
45 
46 
47 unsigned NCstyle::Style::sanitycheck()
48 {
49  return MaxSTglobal;
50 }
51 
52 NCattrset NCstyle::Style::attrGlobal( sanitycheck() );
53 
54 
55 
56 // Initialize subclass StDialog in Style constructor
57 // (esp. copy constructor). Default copy constructor
58 // is not appropriate, because StDialog contains
59 // references to subclass NCattrset.
60 NCstyle::StDialog NCstyle::Style::initDialog()
61 {
62  return StDialog( StBase( attr( DialogTitle ),
63  attr( DialogBorder ) ),
64  StBase( attr( DialogActiveTitle ),
65  attr( DialogActiveBorder ) ),
66  StBase( attr( DialogHeadline ),
67  attr( DialogText ) ),
68  StWidget( attr( DialogDisabled ),
69  attr( DialogDisabled ),
70  attr( DialogDisabled ),
71  attr( DialogDisabled ),
72  attr( DialogDisabled ) ),
73  StWidget( attr( DialogPlain ),
74  attr( DialogLabel ),
75  attr( DialogData ),
76  attr( DialogHint ),
77  attr( DialogScrl ) ),
78  StWidget( attr( DialogActivePlain ),
79  attr( DialogActiveLabel ),
80  attr( DialogActiveData ),
81  attr( DialogActiveHint ),
82  attr( DialogActiveScrl ) ),
83  StWidget( attr( DialogFramePlain ),
84  attr( DialogFrameLabel ),
85  attr( DialogFrameData ),
86  attr( DialogFrameHint ),
87  attr( DialogFrameScrl ) ),
88  StWidget( attr( DialogActiveFramePlain ),
89  attr( DialogActiveFrameLabel ),
90  attr( DialogActiveFrameData ),
91  attr( DialogActiveFrameHint ),
92  attr( DialogActiveFrameScrl ) ),
93  StList( attr( ListTitle ),
94  StItem( attr( ListPlain ),
95  attr( ListLabel ),
96  attr( ListData ),
97  attr( ListHint ) ),
98  StItem( attr( ListSelPlain ),
99  attr( ListSelLabel ),
100  attr( ListSelData ),
101  attr( ListSelHint ) ) ),
102  StList( attr( ListActiveTitle ),
103  StItem( attr( ListActivePlain ),
104  attr( ListActiveLabel ),
105  attr( ListActiveData ),
106  attr( ListActiveHint ) ),
107  StItem( attr( ListActiveSelPlain ),
108  attr( ListActiveSelLabel ),
109  attr( ListActiveSelData ),
110  attr( ListActiveSelHint ) ) ),
111  StList( attr( DialogDisabled ),
112  StItem( attr( DialogDisabled ),
113  attr( DialogDisabled ),
114  attr( DialogDisabled ),
115  attr( DialogDisabled ) ),
116  StItem( attr( DialogDisabled ),
117  attr( DialogDisabled ),
118  attr( DialogDisabled ),
119  attr( DialogDisabled ) ) ),
120  StProgbar( attr( ProgbarCh ),
121  attr( ProgbarBgch ) ),
122  StRichtext( attr( RichTextPlain ),
123  attr( RichTextTitle ),
124  attr( RichTextLink ),
125  attr( RichTextArmedlink ),
126  attr( RichTextActiveArmedlink ),
127  attr( RichTextVisitedLink ),
128  attr( RichTextB ),
129  attr( RichTextI ),
130  attr( RichTextT ),
131  attr( RichTextBI ),
132  attr( RichTextBT ),
133  attr( RichTextIT ),
134  attr( RichTextBIT ) ),
135  attr( TextCursor )
136  );
137 }
138 
139 
140 
141 NCstyle::Style::Style()
142  : NCattrset( MaxSTlocal )
143  , StDialog( initDialog() )
144 {}
145 
146 
147 
148 NCstyle::Style::Style( const Style & rhs )
149  : NCattrset( rhs )
150  , StDialog( initDialog() )
151 {}
152 
153 
154 
155 NCstyle::Style::~Style()
156 {}
157 
158 
159 
160 
161 
162 #define PRT(t) case NCstyle::t: return #t;
163 
164 std::string NCstyle::dumpName( NCstyle::StyleSet a )
165 {
166  switch ( a )
167  {
168  PRT( DefaultStyle );
169  PRT( InfoStyle );
170  PRT( WarnStyle );
171  PRT( PopupStyle );
172 
173  case NCstyle::MaxStyleSet:
174  break;
175  }
176 
177  return "unknown";
178 }
179 
180 std::string NCstyle::dumpName( NCstyle::STglobal a )
181 {
182  switch ( a )
183  {
184  PRT( AppTitle );
185  PRT( AppText );
186 
187  case NCstyle::MaxSTglobal:
188  break;
189  }
190 
191  return "unknown";
192 }
193 
194 std::string NCstyle::dumpName( NCstyle::STlocal a )
195 {
196  switch ( a )
197  {
198  PRT( DialogBorder );
199  PRT( DialogTitle );
200  PRT( DialogActiveBorder );
201  PRT( DialogActiveTitle );
202  //
203  PRT( DialogText );
204  PRT( DialogHeadline );
205  //
206  PRT( DialogDisabled );
207  //
208  PRT( DialogPlain );
209  PRT( DialogLabel );
210  PRT( DialogData );
211  PRT( DialogHint );
212  PRT( DialogScrl );
213  PRT( DialogActivePlain );
214  PRT( DialogActiveLabel );
215  PRT( DialogActiveData );
216  PRT( DialogActiveHint );
217  PRT( DialogActiveScrl );
218  //
219  PRT( DialogFramePlain );
220  PRT( DialogFrameLabel );
221  PRT( DialogFrameData );
222  PRT( DialogFrameHint );
223  PRT( DialogFrameScrl );
224  PRT( DialogActiveFramePlain );
225  PRT( DialogActiveFrameLabel );
226  PRT( DialogActiveFrameData );
227  PRT( DialogActiveFrameHint );
228  PRT( DialogActiveFrameScrl );
229  //
230  PRT( ListTitle );
231  PRT( ListPlain );
232  PRT( ListLabel );
233  PRT( ListData );
234  PRT( ListHint );
235  PRT( ListSelPlain );
236  PRT( ListSelLabel );
237  PRT( ListSelData );
238  PRT( ListSelHint );
239  //
240  PRT( ListActiveTitle );
241  PRT( ListActivePlain );
242  PRT( ListActiveLabel );
243  PRT( ListActiveData );
244  PRT( ListActiveHint );
245  PRT( ListActiveSelPlain );
246  PRT( ListActiveSelLabel );
247  PRT( ListActiveSelData );
248  PRT( ListActiveSelHint );
249  //
250  PRT( RichTextPlain );
251  PRT( RichTextTitle );
252  PRT( RichTextLink );
253  PRT( RichTextArmedlink );
254  PRT( RichTextActiveArmedlink );
255  PRT( RichTextVisitedLink );
256  PRT( RichTextB );
257  PRT( RichTextI );
258  PRT( RichTextT );
259  PRT( RichTextBI );
260  PRT( RichTextBT );
261  PRT( RichTextIT );
262  PRT( RichTextBIT );
263  //
264  PRT( ProgbarCh );
265  PRT( ProgbarBgch );
266  //
267  PRT( TextCursor );
268 
269  case NCstyle::MaxSTlocal:
270  break;
271  }
272 
273  return "unknown";
274 }
275 
276 #undef PRT
277 
278 
279 
280 NCstyle::NCstyle( std::string term_t )
281  : styleName( "linux" )
282  , term( term_t )
283  , styleSet( MaxStyleSet )
284  , fakestyle_e( MaxStyleSet )
285 {
286  char *user_defined_style = getenv( "Y2NCURSES_COLOR_THEME" );
287 
288  if ( user_defined_style && *user_defined_style )
289  {
290  styleName = user_defined_style;
291  yuiMilestone() << "User-defined style found: " << styleName.c_str() << std::endl;
292  }
293  else
294  {
295  if ( NCattribute::colors() )
296  {
297  if ( getenv( "Y2_BRAILLE" ) != NULL )
298  {
299  styleName = "braille";
300  }
301  else
302  {
303  if ( ! fnmatch( "xterm*", term_t.c_str(), 0 ) )
304  styleName = "xterm";
305  else if ( ! fnmatch( "rxvt*", term_t.c_str(), 0 ) )
306  styleName = "rxvt";
307  }
308  }
309  else
310  {
311  styleName = "mono";
312  }
313  }
314 
315  yuiMilestone() << "Init " << term_t << " using " << ( NCattribute::colors() ? "color" : "bw" )
316 
317  << " => " << MaxStyleSet << " styles in " << styleName << std::endl;
318 
319 #define IF_STYLE_INIT(n) if ( styleName == #n ) { NCstyleInit_##n( styleSet ); }
320  IF_STYLE_INIT( linux )
321  else IF_STYLE_INIT( xterm )
322  else IF_STYLE_INIT( rxvt )
323  else IF_STYLE_INIT( mono )
324  else IF_STYLE_INIT( braille )
325  else IF_STYLE_INIT( highcontrast )
326  else IF_STYLE_INIT( inverted )
327  else NCstyleInit_linux( styleSet );
328 }
329 
330 
331 
332 NCstyle::~NCstyle()
333 {
334 }
335 
336 
337 
338 void NCstyle::nextStyle()
339 {
340  if ( !NCattribute::colors() ) return;
341 
342  if ( styleName == "mono" )
343  {
344  if ( term == "xterm" )
345  {
346  styleName = "xterm";
347  NCstyleInit_xterm( styleSet );
348  }
349  else if ( term == "rxvt" )
350  {
351  styleName = "rxvt";
352  NCstyleInit_rxvt( styleSet );
353  }
354  else
355  {
356  styleName = "linux";
357  NCstyleInit_linux( styleSet );
358  }
359  }
360  else if ( styleName == "braille" )
361  {
362  styleName = "mono";
363  NCstyleInit_mono( styleSet );
364  }
365  else
366  {
367  styleName = "braille";
368  NCstyleInit_braille( styleSet );
369  }
370 }
371 
372 
373 
374 void NCstyle::changeSyle()
375 {
376  NCDefineStyle( *this );
377 }
378 
379 
380 
381 void NCstyle::fakestyle( StyleSet f )
382 {
383  fakestyle_e = f;
384  NCurses::Redraw();
385 }