diff options
author | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2012-11-09 21:01:23 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@dside.dyndns.org> | 2012-11-09 21:01:23 +0100 |
commit | 8c8d4f583a460904350b81cf38fed48fd5712cb2 (patch) | |
tree | 02ebced09ae047d193b35aa5e22b6aaa7ee1c2bd | |
parent | 36c055ca75773ce36cc286afe00a1ceefc2449f6 (diff) | |
download | librcc-8c8d4f583a460904350b81cf38fed48fd5712cb2.tar.gz librcc-8c8d4f583a460904350b81cf38fed48fd5712cb2.tar.bz2 librcc-8c8d4f583a460904350b81cf38fed48fd5712cb2.tar.xz librcc-8c8d4f583a460904350b81cf38fed48fd5712cb2.zip |
Initial GTK3 support
-rw-r--r-- | configure.in | 17 | ||||
-rw-r--r-- | examples/Makefile.am | 8 | ||||
-rw-r--r-- | examples/rcc-gtk-config.c | 19 | ||||
-rw-r--r-- | external/rccexternal.c | 2 | ||||
-rw-r--r-- | ui/Makefile.am | 12 | ||||
-rw-r--r-- | ui/gtk.c | 144 |
6 files changed, 162 insertions, 40 deletions
diff --git a/configure.in b/configure.in index 8817d6b..4baa8a3 100644 --- a/configure.in +++ b/configure.in @@ -136,6 +136,22 @@ else fi AM_CONDITIONAL(HAVE_GTK2, [ test $HAVE_GTK2 = yes ]) + +dnl *** +dnl *** GTK 3.0 (Optional) +dnl *** +AC_ARG_ENABLE(gtk3, + [ --disable-gtk3 disable gtk3 [default=enabled]],, + enable_gtk3="yes") + +if test "x$enable_gtk3" = "xyes"; then + PKG_CHECK_MODULES(GTK3, gtk+-3.0 >= 3.0.0, HAVE_GTK3=yes, HAVE_GTK3=no) +else + HAVE_GTK3=no +fi +AM_CONDITIONAL(HAVE_GTK3, [ test $HAVE_GTK3 = yes ]) + + dnl *** dnl *** Shared libraries support dnl *** @@ -407,6 +423,7 @@ echo "" echo "User Interfaces:" echo " GTK User Interface: $HAVE_GTK" echo " GTK2 User Interface: $HAVE_GTK2" +echo " GTK3 User Interface: $HAVE_GTK3" echo "" echo "Directories:" echo " RCC Data Directory: ${rccdir}" diff --git a/examples/Makefile.am b/examples/Makefile.am index 710b7dc..9d6331b 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -18,6 +18,14 @@ rcc_gtk2_config_LDADD=../ui/librccgtk2.la @GTK2_LIBS@ rcc_gtk2_config_CPPFLAGS = @GTK2_CFLAGS@ -I../src -I../ui endif +if HAVE_GTK3 +bin_PROGRAMS+= rcc-gtk3-config +rcc_gtk3_config_SOURCES = rcc-gtk-config.c +rcc_gtk3_config_LDADD=../ui/librccgtk3.la @GTK3_LIBS@ +rcc_gtk3_config_CPPFLAGS = @GTK3_CFLAGS@ -I../src -I../ui +endif + + EXTRA_DIST= input-russian.txt rcc.xml rcc-example.xml mpg123-rcc.patch test: example2 diff --git a/examples/rcc-gtk-config.c b/examples/rcc-gtk-config.c index 6886afd..00d70a3 100644 --- a/examples/rcc-gtk-config.c +++ b/examples/rcc-gtk-config.c @@ -19,6 +19,7 @@ #include <stdio.h> #include <string.h> +#include <locale.h> #include <gtk/gtk.h> #include <librcc.h> @@ -66,7 +67,12 @@ int main (int argc, char *argv[]) if (i==1) printf("Usage: rcc-config [ --all ] [ <config name> ]\n"); +#if GTK_MAJOR_VERSION > 2 + setlocale(LC_ALL, ""); +#else /* GTK_MAJOR_VERSION < 3 */ gtk_set_locale (); +#endif /* GTK_MAJOR_VERSION */ + gtk_init (&argc, &argv); rccInit(); @@ -77,7 +83,11 @@ int main (int argc, char *argv[]) if (all_mode) rccUiUnHideOption(uictx, RCC_OPTION_ALL); window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); +#if GTK_MAJOR_VERSION > 2 + gtk_window_set_resizable(GTK_WINDOW(window1), FALSE); +#else /* GTK_MAJOR_VERSION < 3 */ gtk_window_set_policy(GTK_WINDOW (window1), FALSE, FALSE, TRUE); +#endif /* GTK_MAJOR_VERSION */ gtk_window_set_title (GTK_WINDOW (window1), "LibRCC Config"); gtk_window_set_wmclass (GTK_WINDOW(window1), "librcc", "libRCC"); gtk_widget_show(window1); @@ -92,13 +102,22 @@ int main (int argc, char *argv[]) close = gtk_button_new_with_label("Close"); gtk_widget_show (close); +#if GTK_MAJOR_VERSION > 2 + g_signal_connect (G_OBJECT (window1), "destroy", G_CALLBACK(gtk_main_quit), NULL); + g_signal_connect (G_OBJECT (close), "clicked", G_CALLBACK(gtk_main_quit), NULL); +#else /* GTK_MAJOR_VERSION < 3 */ gtk_signal_connect (GTK_OBJECT (window1), "destroy", GTK_SIGNAL_FUNC (gtk_main_quit), NULL); gtk_signal_connect (GTK_OBJECT (close), "clicked", GTK_SIGNAL_FUNC (gtk_main_quit), NULL); +#endif /* GTK_MAJOR_VERSION */ gtk_box_pack_start (GTK_BOX (hbox), close, FALSE, FALSE, 0); save = gtk_button_new_with_label("Save"); gtk_widget_show (save); +#if GTK_MAJOR_VERSION > 2 + g_signal_connect(G_OBJECT(save), "clicked", G_CALLBACK(apply_cb), NULL); +#else /* GTK_MAJOR_VERSION < 3 */ gtk_signal_connect(GTK_OBJECT(save), "clicked", GTK_SIGNAL_FUNC(apply_cb), NULL); +#endif /* GTK_MAJOR_VERSION */ gtk_box_pack_start (GTK_BOX (hbox), save, FALSE, FALSE, 0); gtk_main (); diff --git a/external/rccexternal.c b/external/rccexternal.c index 2437cd4..cc54430 100644 --- a/external/rccexternal.c +++ b/external/rccexternal.c @@ -56,7 +56,7 @@ # include <signal.h> #endif /* HAVE_SIGNAL_H */ -#include <glib/gthread.h> +#include <glib.h> #include "../src/rcchome.h" #include "../src/rccexternal.h" diff --git a/ui/Makefile.am b/ui/Makefile.am index c41cc8c..3e8679e 100644 --- a/ui/Makefile.am +++ b/ui/Makefile.am @@ -31,5 +31,17 @@ librccgtk2_la_LDFLAGS = -version-info @LIBRCC_VERSION_INFO@ librccgtk2_la_CPPFLAGS = -I../src @XML_INCLUDES@ @GTK2_CFLAGS@ endif +if HAVE_GTK3 +lib_LTLIBRARIES += librccgtk3.la +librccgtk3_la_SOURCES = librccui.c \ + rccmenu.c rccmenu.h \ + rccnames.c rccnames.h \ + internal.h \ + gtk.c +librccgtk3_la_LIBADD = @GTK3_LIBS@ @XML_LIBS@ ../src/librcc.la +librccgtk3_la_LDFLAGS = -version-info @LIBRCC_VERSION_INFO@ +librccgtk3_la_CPPFLAGS = -I../src @XML_INCLUDES@ @GTK3_CFLAGS@ +endif + AM_CPPFLAGS = -I../src @XML_INCLUDES@ include_HEADERS = librccui.h @@ -33,6 +33,13 @@ #define FRAME_BORDER 0 #define PAGE_SPACING 1 +#if GTK_MAJOR_VERSION > 2 +# define gtk_container_border_width gtk_container_set_border_width +# define gtk_widget_set_usize gtk_widget_set_size_request +# define gtk_container_children gtk_container_get_children +#endif /* GTK_MAJOR_VERSION */ + + rcc_ui_internal rccUiCreateInternal(rcc_ui_context ctx) { return NULL; } @@ -48,7 +55,9 @@ void rccUiMenuFreeWidget(rcc_ui_menu_context ctx) { } rcc_ui_id rccUiMenuGet(rcc_ui_menu_context ctx) { +#if GTK_MAJOR_VERSION < 3 GtkWidget *menu; +#endif /* GTK_MAJOR_VERSION */ if (!ctx) return (rcc_ui_id)-1; @@ -65,9 +74,13 @@ rcc_ui_id rccUiMenuGet(rcc_ui_menu_context ctx) { return (rcc_ui_id)-1; } } - + +#if GTK_MAJOR_VERSION > 2 + return gtk_combo_box_get_active(GTK_COMBO_BOX(ctx->widget)); +#else /* GTK_MAJOR_VERSION < 3 */ menu = gtk_option_menu_get_menu(ctx->widget); return g_list_index(GTK_MENU_SHELL(menu)->children, gtk_menu_get_active(GTK_MENU(menu))); +#endif /* GTK_MAJOR_VERSION */ } int rccUiMenuSet(rcc_ui_menu_context ctx, rcc_ui_id id) { @@ -80,7 +93,11 @@ int rccUiMenuSet(rcc_ui_menu_context ctx, rcc_ui_id id) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ctx->widget),id); break; case RCC_OPTION_RANGE_TYPE_MENU: +#if GTK_MAJOR_VERSION > 2 + gtk_combo_box_set_active(GTK_COMBO_BOX(ctx->widget), id); +#else /* GTK_MAJOR_VERSION < 3 */ gtk_option_menu_set_history(ctx->widget, id); +#endif /* GTK_MAJOR_VERSION */ break; case RCC_OPTION_RANGE_TYPE_RANGE: gtk_spin_button_set_value(GTK_SPIN_BUTTON(ctx->widget), id); @@ -89,7 +106,11 @@ int rccUiMenuSet(rcc_ui_menu_context ctx, rcc_ui_id id) { } break; default: +#if GTK_MAJOR_VERSION > 2 + gtk_combo_box_set_active(GTK_COMBO_BOX(ctx->widget), id); +#else /* GTK_MAJOR_VERSION < 3 */ gtk_option_menu_set_history(ctx->widget, id); +#endif /* GTK_MAJOR_VERSION */ } return 0; @@ -113,6 +134,7 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { rcc_class_id class_id; rcc_charset_id charset_id; rcc_engine_id engine_id; + gint value_id; const char *language; const char *charset; @@ -122,40 +144,63 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { rcc_option_name *option_name; rcc_option_value_names optnames; - GtkWidget *list, *item, *menu; + GtkWidget *menu; + GtkWidget *item; +#if GTK_MAJOR_VERSION > 2 + GtkAdjustment *adjustment; +#else /* GTK_MAJOR_VERSION < 3 */ + GtkWidget *list; GtkObject *adjustment; +#endif /* GTK_MAJOR_VERSION */ if (!ctx) return -1; uictx = ctx->uictx; rccctx = uictx->rccctx; - + switch (ctx->type) { case RCC_UI_MENU_LANGUAGE: - num = rccGetLanguageNumber(rccctx); - + case RCC_UI_MENU_CHARSET: + case RCC_UI_MENU_ENGINE: + if (ctx->widget) menu = ctx->widget; + else +#if GTK_MAJOR_VERSION > 2 + menu = gtk_combo_box_text_new(); + gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(menu)); +#else /* GTK_MAJOR_VERSION < 3 */ + menu = gtk_option_menu_new(); + gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu)); list = gtk_menu_new(); +#endif /* GTK_MAJOR_VERSION */ + + ctx->widget = menu; + break; + default: + ; + } + + switch (ctx->type) { + case RCC_UI_MENU_LANGUAGE: + num = rccGetLanguageNumber(rccctx); + for (i=0; i<(num?num:1); i++) { language = rccUiGetLanguageName(uictx, (rcc_language_id)i); if (!language) continue; +#if GTK_MAJOR_VERSION > 2 + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(menu), NULL, language); +#else /* GTK_MAJOR_VERSION < 3 */ item = gtk_menu_item_new_with_label(language); gtk_widget_show(item); - gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(rccGtkMenuLanguageCB), ctx); + gtk_signal_connect(GTK_OBJECT(item), "activate", GTK_SIGNAL_FUNC(rccGtkMenuLanguageCB), ctx); gtk_menu_append(GTK_MENU(list), item); +#endif /* GTK_MAJOR_VERSION */ } language_id = rccGetSelectedLanguage(rccctx); if (language_id == (rcc_language_id)-1) language_id = 0; - if (ctx->widget) menu = ctx->widget; - else { - menu = gtk_option_menu_new(); - ctx->widget = menu; - } - gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu)); - gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list); - gtk_option_menu_set_history(GTK_OPTION_MENU(menu), language_id); + value_id = language_id; break; case RCC_UI_MENU_CHARSET: language_id = (rcc_language_id)rccUiMenuGet(uictx->language); @@ -163,59 +208,47 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { config = rccGetConfig(rccctx, language_id); num = rccConfigGetClassCharsetNumber(config, class_id); - list = gtk_menu_new(); for (i=0;i<(num?num:1);i++) { charset = rccUiGetCharsetName(uictx, language_id, class_id, (rcc_charset_id)i); if (!charset) continue; +#if GTK_MAJOR_VERSION > 2 + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(menu), NULL, charset); +#else /* GTK_MAJOR_VERSION < 3 */ item = gtk_menu_item_new_with_label(charset); if (rccIsDisabledCharsetName(rccctx, class_id, charset)) gtk_widget_set_sensitive(item, 0); else gtk_widget_show(item); gtk_menu_append(GTK_MENU(list), item); - } - - if (ctx->widget) menu = ctx->widget; - else { - menu = gtk_option_menu_new(); - ctx->widget = menu; +#endif /* GTK_MAJOR_VERSION */ } - gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu)); - gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list); - charset_id = rccConfigGetSelectedCharset(config, class_id); if (charset_id == (rcc_charset_id)-1) charset_id = 0; - gtk_option_menu_set_history(GTK_OPTION_MENU(menu), charset_id); + value_id = charset_id; break; case RCC_UI_MENU_ENGINE: - language_id = (rcc_language_id)rccUiMenuGet(uictx->language); config = rccGetConfig(rccctx, language_id); num = rccConfigGetEngineNumber(config); - list = gtk_menu_new(); for (i=0;i<(num?num:1);i++) { engine = rccUiGetEngineName(uictx, language_id, (rcc_engine_id)i); if (!engine) continue; +#if GTK_MAJOR_VERSION > 2 + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(menu), NULL, engine); +#else /* GTK_MAJOR_VERSION < 3 */ item = gtk_menu_item_new_with_label(engine); gtk_widget_show(item); gtk_menu_append(GTK_MENU(list), item); +#endif /* GTK_MAJOR_VERSION */ } - if (ctx->widget) menu = ctx->widget; - else { - menu = gtk_option_menu_new(); - ctx->widget = menu; - } - - gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu)); - gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list); engine_id = rccConfigGetCurrentEngine(config); if (engine_id == (rcc_engine_id)-1) engine_id = 0; - gtk_option_menu_set_history(GTK_OPTION_MENU(menu), engine_id); + value_id = engine_id; break; case RCC_UI_MENU_OPTION: switch (rccUiMenuGetRangeType(ctx)) { @@ -233,20 +266,32 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { optnames = option_name->value_names; if (!optnames) return -1; +#if GTK_MAJOR_VERSION > 2 + menu = gtk_combo_box_text_new(); + for (i=0;optnames[i];i++) { + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(menu), NULL, optnames[i]); + } +#else /* GTK_MAJOR_VERSION < 3 */ list = gtk_menu_new(); for (i=0;optnames[i];i++) { item = gtk_menu_item_new_with_label(optnames[i]); gtk_widget_show(item); gtk_menu_append(GTK_MENU(list), item); } - + menu = gtk_option_menu_new(); - ctx->widget = menu; gtk_option_menu_remove_menu(GTK_OPTION_MENU(menu)); gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list); +#endif /* GTK_MAJOR_VERSION */ + + ctx->widget = menu; } +#if GTK_MAJOR_VERSION > 2 + gtk_combo_box_set_active(GTK_COMBO_BOX(ctx->widget), rccGetOption(rccctx, rccUiMenuGetOption(ctx))); +#else /* GTK_MAJOR_VERSION < 3 */ gtk_option_menu_set_history(GTK_OPTION_MENU(ctx->widget), rccGetOption(rccctx, rccUiMenuGetOption(ctx))); +#endif /* GTK_MAJOR_VERSION */ break; case RCC_OPTION_RANGE_TYPE_RANGE: range = rccUiMenuGetRange(ctx); @@ -264,13 +309,34 @@ int rccUiMenuConfigureWidget(rcc_ui_menu_context ctx) { return -1; } + + switch (ctx->type) { + case RCC_UI_MENU_LANGUAGE: +#if GTK_MAJOR_VERSION > 2 + g_signal_connect(G_OBJECT(menu), "changed", G_CALLBACK(rccGtkMenuLanguageCB), ctx); +#endif /* GTK_MAJOR_VERSION */ + + case RCC_UI_MENU_CHARSET: + case RCC_UI_MENU_ENGINE: +#if GTK_MAJOR_VERSION > 2 + gtk_combo_box_set_active(GTK_COMBO_BOX(menu), value_id); +#else /* GTK_MAJOR_VERSION < 3 */ + gtk_option_menu_set_menu(GTK_OPTION_MENU(menu), list); + gtk_option_menu_set_history(GTK_OPTION_MENU(menu), value_id); +#endif /* GTK_MAJOR_VERSION */ + + break; + default: + ; + } + return 0; } - rcc_ui_box rccUiBoxCreate(rcc_ui_menu_context ctx, const char *title) { GtkWidget *hbox, *label; hbox = gtk_hbox_new(FALSE, BOX_SPACING); + gtk_container_border_width(GTK_CONTAINER(hbox), BOX_BORDER); if ((ctx->type != RCC_UI_MENU_OPTION)||(rccUiMenuGetRangeType(ctx) != RCC_OPTION_RANGE_TYPE_BOOLEAN)) { label = gtk_label_new(title); |