2 /*******************************************************************************/
3 /* Copyright (C) 2012 Jonathan Moore Liles */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
20 #include "FL/Fl_Theme.H"
22 #include <FL/Fl_Window.H>
23 #include <FL/Fl_Preferences.H>
25 Fl_Theme *Fl_Theme::first;
26 Fl_Theme *Fl_Theme::_current;
27 Fl_Color_Scheme *Fl_Color_Scheme::first;
30 int Fl_Color_Scheme::total;
33 Fl_Theme::add ( Fl_Theme *t )
41 Fl_Theme::get ( void )
43 Fl_Theme **r = (Fl_Theme**) malloc( sizeof( Fl_Theme* ) * ( total + 1 ) );
46 for ( Fl_Theme *t = first; t; t = t->next, i++ )
56 Fl_Preferences *prefs ( void )
60 asprintf( &path, "%s/.config/ntk/", getenv("HOME" ) );
62 Fl_Preferences *p = new Fl_Preferences( path, "ntk", "theme" );
69 static void conf_set ( const char *key, const char *value )
71 Fl_Preferences *p = prefs();
78 static void conf_set ( const char *key, Fl_Color value )
80 Fl_Preferences *p = prefs();
82 p->set( key, (int)value );
87 static const char *conf_get ( const char *key, const char *def )
91 Fl_Preferences *p = prefs();
93 p->get( key, buf, def, sizeof( buf ) );
102 conf_get_color ( const char *key, Fl_Color def )
104 Fl_Preferences *p = prefs();
108 p->get( key, c, def );
115 static bool dont_save = false;
117 /* sets the configured default */
119 Fl_Theme::set ( void )
121 const char *name = conf_get( "theme", "clean" );
123 int rv = set( name );
127 Fl_Color_Scheme::set( "System" );
133 Fl::get_color( conf_get_color( "background", FL_BACKGROUND_COLOR ), r, g, b );
134 Fl::background( r, g, b );
135 Fl::get_color( conf_get_color( "background2", FL_BACKGROUND2_COLOR ), r, g, b );
136 Fl::background2( r, g, b );
137 Fl::get_color( conf_get_color( "foreground", FL_FOREGROUND_COLOR ), r, g, b );
138 Fl::foreground( r, g, b );
144 Fl_Theme::set ( const char *name )
146 for ( Fl_Theme *t = first; t; t = t->next )
147 if ( !strcasecmp( t->name(), name ) )
152 printf( "Theme set to %s\n", t->name() );
154 Fl_Theme::_current = t;
156 conf_set( "theme", t->name() );
158 for ( Fl_Window *w = Fl::first_window(); w; w = Fl::next_window( w ) )
168 Fl_Color_Scheme::add ( Fl_Color_Scheme *t )
176 Fl_Color_Scheme::get ( void )
178 Fl_Color_Scheme **r = (Fl_Color_Scheme**) malloc( sizeof( Fl_Color_Scheme* ) * ( total + 1 ) );
181 for ( Fl_Color_Scheme *t = first; t; t = t->next, i++ )
190 Fl_Color_Scheme::save ( void )
194 conf_set( "background", Fl::get_color( FL_BACKGROUND_COLOR ) );
195 conf_set( "foreground", Fl::get_color( FL_FOREGROUND_COLOR ) );
196 conf_set( "background2", Fl::get_color( FL_BACKGROUND2_COLOR ) );
199 for ( Fl_Window *w = Fl::first_window(); w; w = Fl::next_window( w ) )
204 Fl_Color_Scheme::set ( const char *name )
206 for ( Fl_Color_Scheme *t = first; t; t = t->next )
207 if ( !strcasecmp( t->name(), name ) )
211 Fl::get_color( t->_bg, r, g, b );
212 Fl::background( r, g, b );
213 Fl::get_color( t->_bg2, r, g, b );
214 Fl::background2( r, g, b );
215 Fl::get_color( t->_fg, r, g, b );
216 Fl::foreground( r, g, b );
217 /* Fl::get_color( t->_sel, r, g, b ); */
218 /* Fl::selection( r, g, b ); */
220 conf_set( "color_scheme", t->name() );