reformat gtktheme.cpp
This commit is contained in:
parent
a5865dce55
commit
b8f2cffa3f
|
|
@ -21,20 +21,16 @@
|
|||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
|
||||
#include "gtktheme.h"
|
||||
#include "mainframe.h"
|
||||
//#include "gtkutil/window.h"
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
|
||||
std::string& get_orig_theme();
|
||||
std::string& get_orig_font();
|
||||
|
||||
|
|
@ -48,23 +44,15 @@ void set_theme(const std::string& theme_name, const std::string& font);
|
|||
void apply_theme( const std::string& theme_name, const std::string& font );
|
||||
|
||||
|
||||
|
||||
GtkWidget* g_main_rc_window = NULL;
|
||||
|
||||
|
||||
static std::string s_rc_file;
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
GtkWidget* lookup_widget( GtkWidget* widget, const gchar* widget_name ) {
|
||||
GtkWidget* parent, *found_widget;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for( ;; ) {
|
||||
if( GTK_IS_MENU( widget ) )
|
||||
parent = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
|
||||
else
|
||||
|
|
@ -76,8 +64,7 @@ GtkWidget* lookup_widget (GtkWidget *widget, const gchar *widget_name){
|
|||
widget = parent;
|
||||
}
|
||||
|
||||
found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
|
||||
widget_name);
|
||||
found_widget = (GtkWidget*)g_object_get_data( G_OBJECT( widget ), widget_name );
|
||||
if( !found_widget )
|
||||
g_warning( "Widget not found: %s", widget_name );
|
||||
return found_widget;
|
||||
|
|
@ -85,21 +72,16 @@ GtkWidget* lookup_widget (GtkWidget *widget, const gchar *widget_name){
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void on_main_cancel_button_clicked( GtkButton* button, gpointer user_data ) {
|
||||
set_theme( get_orig_theme(), get_orig_font() );
|
||||
gtk_widget_destroy( g_main_rc_window );
|
||||
g_main_rc_window = NULL;
|
||||
}
|
||||
|
||||
|
||||
void on_main_reset_button_clicked( GtkButton* button, gpointer user_data ) {
|
||||
set_theme( get_orig_theme(), get_orig_font() );
|
||||
}
|
||||
|
||||
|
||||
gboolean on_main_window_delete_event( GtkWidget* widget, GdkEvent* event, gpointer user_data ) {
|
||||
set_theme( get_orig_theme(), get_orig_font() );
|
||||
gtk_widget_destroy( g_main_rc_window );
|
||||
|
|
@ -107,16 +89,12 @@ gboolean on_main_window_delete_event(GtkWidget *widget, GdkEvent *event, gpointe
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void on_main_use_default_font_radio_toggled( GtkToggleButton* togglebutton, gpointer user_data ) {
|
||||
bool default_font = gtk_toggle_button_get_active( togglebutton );
|
||||
|
||||
const bool default_font = gtk_toggle_button_get_active( togglebutton );
|
||||
gtk_widget_set_sensitive( lookup_widget( g_main_rc_window, "main_font_selector_button" ), !default_font );
|
||||
|
||||
apply_theme( get_selected_theme(), get_selected_font() );
|
||||
}
|
||||
|
||||
|
||||
void on_main_font_selector_button_font_set( GtkFontButton* fontbutton, gpointer user_data ) {
|
||||
apply_theme( get_selected_theme(), get_selected_font() );
|
||||
}
|
||||
|
|
@ -127,7 +105,6 @@ void on_main_ok_button_clicked( GtkButton *button, gpointer user_data ){
|
|||
}
|
||||
|
||||
|
||||
|
||||
#define GLADE_HOOKUP_OBJECT( component, widget, name ) \
|
||||
g_object_set_data_full( G_OBJECT( component ), name, \
|
||||
gtk_widget_ref( widget ), (GDestroyNotify)gtk_widget_unref )
|
||||
|
|
@ -135,9 +112,7 @@ void on_main_ok_button_clicked( GtkButton *button, gpointer user_data ){
|
|||
#define GLADE_HOOKUP_OBJECT_NO_REF( component, widget, name ) \
|
||||
g_object_set_data( G_OBJECT( component ), name, widget )
|
||||
|
||||
GtkWidget*
|
||||
create_rc_window (void)
|
||||
{
|
||||
GtkWidget* create_rc_window() {
|
||||
GtkWidget* main_window;
|
||||
GtkWidget* main_hbox;
|
||||
GtkWidget* vbox1;
|
||||
|
|
@ -442,40 +417,28 @@ create_rc_window (void)
|
|||
|
||||
|
||||
|
||||
|
||||
static std::string gchar_to_string(gchar* gstr)
|
||||
{
|
||||
static std::string gchar_to_string( gchar* gstr ) {
|
||||
std::string str = ( gstr ? gstr : "" );
|
||||
g_free( gstr );
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
|
||||
static std::string s_orig_theme;
|
||||
static std::string s_orig_font;
|
||||
|
||||
std::string& get_orig_theme()
|
||||
{
|
||||
std::string& get_orig_theme() {
|
||||
return s_orig_theme;
|
||||
}
|
||||
|
||||
|
||||
std::string& get_orig_font()
|
||||
{
|
||||
std::string& get_orig_font() {
|
||||
return s_orig_font;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
|
||||
std::string get_current_theme()
|
||||
{
|
||||
|
||||
std::string get_current_theme() {
|
||||
GtkSettings* settings = gtk_settings_get_default();
|
||||
gchar* theme;
|
||||
g_object_get( settings, "gtk-theme-name", &theme, NULL );
|
||||
|
|
@ -488,22 +451,13 @@ std::string get_current_theme()
|
|||
return gchar_to_string( theme );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::string get_current_font()
|
||||
{
|
||||
std::string get_current_font() {
|
||||
return gchar_to_string( pango_font_description_to_string( gtk_rc_get_style( g_main_rc_window )->font_desc ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
std::string get_selected_theme()
|
||||
{
|
||||
std::string get_selected_theme() {
|
||||
GtkTreeView* treeview = GTK_TREE_VIEW( lookup_widget( g_main_rc_window, "main_themelist" ) );
|
||||
GtkTreeModel* model = gtk_tree_view_get_model( treeview );
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection( treeview );
|
||||
|
|
@ -517,15 +471,11 @@ std::string get_selected_theme()
|
|||
return gchar_to_string( theme_name );
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string get_selected_font()
|
||||
{
|
||||
std::string get_selected_font() {
|
||||
// GtkWidget* fontentry = lookup_widget( g_main_rc_window, "main_fontentry" );
|
||||
// return gtk_entry_get_text( GTK_ENTRY( fontentry ) );
|
||||
|
||||
bool default_font = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(g_main_rc_window, "main_use_default_font_radio")));
|
||||
|
||||
const bool default_font = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( lookup_widget( g_main_rc_window, "main_use_default_font_radio" ) ) );
|
||||
if( default_font )
|
||||
return "";
|
||||
|
||||
|
|
@ -535,24 +485,14 @@ std::string get_selected_font()
|
|||
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
static void themelist_selection_changed_cb(GtkTreeSelection* selection, gpointer data)
|
||||
{
|
||||
static void themelist_selection_changed_cb( GtkTreeSelection* selection, gpointer data ) {
|
||||
if( gtk_tree_selection_get_selected( selection, 0, 0 ) )
|
||||
apply_theme( get_selected_theme(), get_current_font() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
static void populate_with_themes(GtkWidget* w)
|
||||
{
|
||||
|
||||
static void populate_with_themes( GtkWidget* w ) {
|
||||
std::string search_path = gchar_to_string( gtk_rc_get_theme_dir() );
|
||||
|
||||
if( search_path.size() && search_path[search_path.size() - 1] != G_DIR_SEPARATOR )
|
||||
|
|
@ -562,7 +502,6 @@ static void populate_with_themes(GtkWidget* w)
|
|||
if( gdir == NULL )
|
||||
return;
|
||||
|
||||
|
||||
char* name;
|
||||
GList* glist = 0;
|
||||
|
||||
|
|
@ -573,7 +512,11 @@ static void populate_with_themes(GtkWidget* w)
|
|||
// continue;
|
||||
|
||||
std::string fullname = search_path + filename;
|
||||
std::string rc = fullname; rc += G_DIR_SEPARATOR_S; rc += "gtk-2.0"; rc += G_DIR_SEPARATOR_S; rc += "gtkrc";
|
||||
std::string rc = fullname;
|
||||
rc += G_DIR_SEPARATOR_S;
|
||||
rc += "gtk-2.0";
|
||||
rc += G_DIR_SEPARATOR_S;
|
||||
rc += "gtkrc";
|
||||
|
||||
bool is_dir = 0;
|
||||
if( g_file_test( fullname.c_str(), G_FILE_TEST_IS_DIR ) )
|
||||
|
|
@ -586,12 +529,7 @@ static void populate_with_themes(GtkWidget* w)
|
|||
|
||||
g_dir_close( gdir );
|
||||
|
||||
|
||||
|
||||
|
||||
// ---------------- tree
|
||||
|
||||
|
||||
GtkTreeView* treeview = GTK_TREE_VIEW( w );
|
||||
GtkListStore* store = gtk_list_store_new( 1, G_TYPE_STRING );
|
||||
gtk_tree_view_set_model( treeview, GTK_TREE_MODEL( store ) );
|
||||
|
|
@ -603,9 +541,7 @@ static void populate_with_themes(GtkWidget* w)
|
|||
gtk_tree_view_column_set_sizing( column, GTK_TREE_VIEW_COLUMN_GROW_ONLY );
|
||||
gtk_tree_view_append_column( GTK_TREE_VIEW( treeview ), column );
|
||||
|
||||
|
||||
GtkTreeIter iter;
|
||||
|
||||
int i = 0, curr = 0;
|
||||
while( char* theme = (char*)g_list_nth_data( glist, i ) ) {
|
||||
gtk_list_store_append( store, &iter );
|
||||
|
|
@ -614,11 +550,9 @@ static void populate_with_themes(GtkWidget* w)
|
|||
if( strcmp( theme, get_current_theme().c_str() ) == 0 ) {
|
||||
curr = i;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
|
||||
GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( treeview ) );
|
||||
|
||||
// set the default theme
|
||||
|
|
@ -640,26 +574,16 @@ static void populate_with_themes(GtkWidget* w)
|
|||
|
||||
g_object_unref( G_OBJECT( store ) );
|
||||
|
||||
|
||||
// ---------------- font
|
||||
|
||||
|
||||
GtkWidget* fontbutton = lookup_widget( g_main_rc_window, "main_font_selector_button" );
|
||||
gtk_font_button_set_font_name( GTK_FONT_BUTTON( fontbutton ), get_current_font().c_str() );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
void gtkThemeDlg() {
|
||||
if( g_main_rc_window ) return;
|
||||
if( g_main_rc_window )
|
||||
return;
|
||||
|
||||
s_rc_file = std::string( AppPath_get() ) + G_DIR_SEPARATOR_S + ".gtkrc-2.0.radiant";
|
||||
|
||||
|
|
@ -674,14 +598,10 @@ void gtkThemeDlg(){
|
|||
}
|
||||
|
||||
|
||||
|
||||
// -------------------------------
|
||||
|
||||
|
||||
|
||||
void set_theme(const std::string& theme_name, const std::string& font)
|
||||
{
|
||||
if( theme_name.empty() ) return;
|
||||
void set_theme( const std::string& theme_name, const std::string& font ) {
|
||||
if( theme_name.empty() )
|
||||
return;
|
||||
|
||||
// tree
|
||||
GtkTreeView* treeview = GTK_TREE_VIEW( lookup_widget( g_main_rc_window, "main_themelist" ) );
|
||||
|
|
@ -692,7 +612,6 @@ void set_theme(const std::string& theme_name, const std::string& font)
|
|||
gtk_tree_model_get_iter_first( model, &iter );
|
||||
|
||||
while( gtk_tree_model_iter_next( model, &iter ) ) {
|
||||
|
||||
gchar* text;
|
||||
gtk_tree_model_get( model, &iter, 0, &text, -1 );
|
||||
std::string theme = gchar_to_string( text );
|
||||
|
|
@ -701,10 +620,8 @@ void set_theme(const std::string& theme_name, const std::string& font)
|
|||
gtk_tree_selection_select_iter( selection, &iter );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// font
|
||||
if( font != "" ) {
|
||||
GtkWidget* fontbutton = lookup_widget( g_main_rc_window, "main_font_selector_button" );
|
||||
|
|
@ -712,17 +629,10 @@ void set_theme(const std::string& theme_name, const std::string& font)
|
|||
gtk_font_button_set_font_name( GTK_FONT_BUTTON( fontbutton ), font.c_str() );
|
||||
}
|
||||
|
||||
|
||||
apply_theme( get_selected_theme(), get_selected_font() );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void apply_theme(const std::string& theme_name, const std::string& font)
|
||||
{
|
||||
|
||||
void apply_theme( const std::string& theme_name, const std::string& font ) {
|
||||
std::stringstream strstr;
|
||||
strstr << "gtk-theme-name = \"" << theme_name << "\"\n";
|
||||
|
||||
|
|
@ -737,7 +647,6 @@ void apply_theme(const std::string& theme_name, const std::string& font)
|
|||
f << strstr.str();
|
||||
f.close();
|
||||
|
||||
|
||||
GtkSettings* settings = gtk_settings_get_default();
|
||||
|
||||
gtk_rc_reparse_all_for_settings( settings, true );
|
||||
|
|
@ -749,6 +658,4 @@ void apply_theme(const std::string& theme_name, const std::string& font)
|
|||
|
||||
while( gtk_events_pending() )
|
||||
gtk_main_iteration();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user