svnno****@sourc*****
svnno****@sourc*****
Sun Feb 15 09:17:04 JST 2009
Revision: 3694 http://svn.sourceforge.jp/view?root=kazehakase&view=rev&rev=3694 Author: ikezoe Date: 2009-02-15 09:17:04 +0900 (Sun, 15 Feb 2009) Log Message: ----------- * src/kz-bin.[ch]: Added wrapping KzEmbed in KzNotebook to switch layout engine. * src/kz-window.[ch], src/kz-notebook.[ch], src/actions/kz-actions.c, etc/kz-ui-expert.xml.in: Switch layout engine. SwitchLayoutEngine is now created on building time. It should be created at run time. Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/etc/kz-ui-expert.xml.in kazehakase/trunk/src/actions/kz-actions.c kazehakase/trunk/src/kz-notebook.c kazehakase/trunk/src/kz-notebook.h kazehakase/trunk/src/kz-window.c kazehakase/trunk/src/kz-window.h kazehakase/trunk/src/widget/Makefile.am Added Paths: ----------- kazehakase/trunk/src/widget/kz-bin.c kazehakase/trunk/src/widget/kz-bin.h Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2009-02-14 23:11:21 UTC (rev 3693) +++ kazehakase/trunk/ChangeLog 2009-02-15 00:17:04 UTC (rev 3694) @@ -3,6 +3,11 @@ * src/kz-embed.c: suppress warnings. * src/kz-tab-label.c: KzEmbed property is not G_PARAM_CONSTRUCT_ONLY. * src/kz-tab-label.[ch]: Added kz_tab_label_set_embed. + * src/kz-bin.[ch]: Added wrapping KzEmbed in KzNotebook to switch + layout engine. + * src/kz-window.[ch], src/kz-notebook.[ch], src/actions/kz-actions.c, + etc/kz-ui-expert.xml.in: Switch layout engine. SwitchLayoutEngine is + now created on building time. It should be created at run time. 2009-02-14 Hiroyuki Ikezoe <poinc****@ikezo*****> Modified: kazehakase/trunk/etc/kz-ui-expert.xml.in =================================================================== --- kazehakase/trunk/etc/kz-ui-expert.xml.in 2009-02-14 23:11:21 UTC (rev 3693) +++ kazehakase/trunk/etc/kz-ui-expert.xml.in 2009-02-15 00:17:04 UTC (rev 3694) @@ -69,6 +69,12 @@ </menu> <separator name="view-sep5" /> <menuitem name="ToggleFullScreen" action="ToggleFullScreen" /> + <separator name="view-sep6" /> + <menu name="SwitchLayoutEngineMenu" action="StockSwitchLayoutEngineMenu"> + <menuitem name="Gecko" action="Gecko" /> + <menuitem name="WebKit/GTK+" action="WebKit/GTK+" /> + <menuitem name="IE" action="IE" /> + </menu> </menu> <menu name="GoMenu" action="StockGoMenu"> Modified: kazehakase/trunk/src/actions/kz-actions.c =================================================================== --- kazehakase/trunk/src/actions/kz-actions.c 2009-02-14 23:11:21 UTC (rev 3693) +++ kazehakase/trunk/src/actions/kz-actions.c 2009-02-15 00:17:04 UTC (rev 3694) @@ -74,10 +74,20 @@ UI_CUSTOM }; +enum { +#ifdef WITH_GECKO + KZ_LAYOUT_ENGINE_GECKO, +#endif +#ifdef WITH_WEBKIT_GTK + KZ_LAYOUT_ENGINE_WEBKIT_GTK, +#endif +#ifdef WITH_GTK_IE_EMBED + KZ_LAYOUT_ENGINE_GTK_IE_EMBED, +#endif +}; static GQuark bookmark_quark = 0; - static void act_save (GtkAction *action, KzWindow *kz) { @@ -838,7 +848,40 @@ gtk_notebook_set_tab_pos(GTK_NOTEBOOK(kz->notebook), value); } +static void +act_switch_layout_engine (GtkRadioAction *action, GtkRadioAction *cur_action, KzWindow *kz) +{ + gint value; + const gchar *engine_name = NULL; + value = gtk_radio_action_get_current_value(action); + switch (value) + { +#ifdef WITH_GECKO + case KZ_LAYOUT_ENGINE_GECKO: + engine_name = "gecko"; + break; +#endif +#ifdef WITH_WEBKIT_GTK + case KZ_LAYOUT_ENGINE_WEBKIT_GTK: + engine_name = "webkit_gtk"; + break; +#endif +#ifdef WITH_GTK_IE_EMBED + case KZ_LAYOUT_ENGINE_GTK_IE_EMBED: + engine_name = "ie"; + break; +#endif + default: + break; + } + + if (!engine_name) + return; + + kz_window_switch_layout_engine(kz, engine_name); +} + static void close_tabs (KzNotebook *notebook, KzNotebookCloseCondition condition) { @@ -1708,6 +1751,7 @@ {"StockProxyMenu", NULL, N_("Proxy"), NULL, NULL, NULL}, {"StockRecentCloseTabMenu", NULL, N_("Recent closed tabs"), NULL, NULL, NULL}, {"StockClipMenu", NULL, N_("Clip"), NULL, NULL, NULL}, + {"StockSwitchLayoutEngineMenu", NULL, N_("Switch layout engine"), NULL, NULL, NULL}, {"NewWindow", KZ_STOCK_NEW_WINDOW, N_("_New Window"), CTRL"N", N_("Open a new window"), G_CALLBACK(act_new_window)}, {"NewTab", GTK_STOCK_NEW, N_("New _Tab"), CTRL"T", N_("Open a new tab"), G_CALLBACK(act_new_tab)}, @@ -1860,6 +1904,19 @@ }; static const gint kz_tab_pos_radio_actions_len = G_N_ELEMENTS(kz_tab_pos_radio_actions); +static GtkRadioActionEntry kz_switch_layout_engine_radio_actions[] = +{ +#ifdef WITH_GECKO + {"Gecko", NULL, N_("Gecko"), NULL, NULL, KZ_LAYOUT_ENGINE_GECKO}, +#endif +#ifdef WITH_WEBKIT_GTK + {"WebKit/GTK+", NULL, N_("WebKit/GTK+"), NULL, NULL, KZ_LAYOUT_ENGINE_WEBKIT_GTK}, +#endif +#ifdef WITH_GTK_IE_EMBED + {"IE", NULL, N_("InternetExplorer"), NULL, NULL, KZ_LAYOUT_ENGINE_GTK_IE_EMBED}, +#endif +}; +static const gint kz_switch_layout_engine_radio_actions_len = G_N_ELEMENTS(kz_switch_layout_engine_radio_actions); static void set_popup_menu_sensitive (KzWindow *kz, KzBookmark *bookmark) @@ -2316,6 +2373,12 @@ -1, G_CALLBACK(act_tab_pos), kz); + gtk_action_group_add_radio_actions(action_group, + kz_switch_layout_engine_radio_actions, + kz_switch_layout_engine_radio_actions_len, + -1, + G_CALLBACK(act_switch_layout_engine), + kz); #if 1 /* Back and Forward Action */ { Modified: kazehakase/trunk/src/kz-notebook.c =================================================================== --- kazehakase/trunk/src/kz-notebook.c 2009-02-14 23:11:21 UTC (rev 3693) +++ kazehakase/trunk/src/kz-notebook.c 2009-02-15 00:17:04 UTC (rev 3694) @@ -27,6 +27,7 @@ #include "gtk-utils.h" #include "kz-tab-label.h" #include "kz-actions.h" +#include "kz-bin.h" static const gpointer KZ_NOTEBOOK_GROUP = "KzNotebookGroup"; @@ -453,9 +454,13 @@ { KzNotebookPrivate *priv = KZ_NOTEBOOK_GET_PRIVATE(notebook); gint inserted_pos; + GtkWidget *bin; + bin = kz_bin_new(); + gtk_container_add(GTK_CONTAINER(bin), GTK_WIDGET(embed)); + gtk_widget_show(bin); inserted_pos = gtk_notebook_insert_page(GTK_NOTEBOOK(notebook), - GTK_WIDGET(embed), + bin, GTK_WIDGET(label), pos); @@ -533,7 +538,7 @@ GNode *node, *child; KzEmbed *current = kz_notebook_get_nth_embed(notebook, gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook))); - kztab = kz_notebook_get_tab_label(KZ_NOTEBOOK(notebook), embed); + kztab = kz_notebook_get_tab_label(notebook, embed); if (kztab && kz_tab_label_get_lock(kztab)) { @@ -608,7 +613,7 @@ g_node_destroy(node); } - gtk_widget_destroy(GTK_WIDGET(embed)); + gtk_widget_destroy(gtk_widget_get_parent(GTK_WIDGET(embed))); if (kz && gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook)) == 0) { @@ -789,7 +794,7 @@ widget = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), page_num); - return KZ_EMBED(widget); + return widget ? KZ_EMBED(gtk_bin_get_child(GTK_BIN(widget))) : NULL; } KzTabLabel * @@ -797,9 +802,9 @@ { GtkWidget *widget; - widget = GTK_WIDGET(embed); + widget = gtk_widget_get_parent(GTK_WIDGET(embed)); - return KZ_TAB_LABEL(gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook), widget)); + return widget ? KZ_TAB_LABEL(gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook), widget)) : NULL; } KzTabLabel * @@ -873,7 +878,7 @@ kz_notebook_get_sibling_tab_label (KzNotebook *notebook, KzTabLabel *label) { KzEmbed *sibembed; - GtkWidget *widget; + KzTabLabel *kztab; g_return_val_if_fail(KZ_IS_NOTEBOOK(notebook), NULL); g_return_val_if_fail(KZ_IS_TAB_LABEL(label), NULL); @@ -883,8 +888,8 @@ if (!sibembed) return NULL; - widget = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook), GTK_WIDGET(sibembed)); - return widget ? KZ_TAB_LABEL(widget) : NULL; + kztab = kz_notebook_get_tab_label(notebook, sibembed); + return kztab; } GtkWidget * @@ -906,16 +911,25 @@ } void -kz_notebook_foreach_page (KzNotebook *notebook, - GFunc func, - gpointer user_data) +kz_notebook_foreach_embed (KzNotebook *notebook, + GFunc func, + gpointer user_data) { - GList *pages; + GList *pages, *node; - pages = gtk_container_get_children(GTK_CONTAINER(notebook)); - if (!pages) - return; - g_list_foreach(pages, func, user_data); - g_list_free(pages); + pages = gtk_container_get_children(GTK_CONTAINER(notebook)); + if (!pages) + return; + + for (node = pages; node; node = g_list_next(node)) + { + GtkWidget *bin = node->data; + GtkWidget *embed; + embed = gtk_bin_get_child(GTK_BIN(bin)); + if (!embed) + continue; + func(embed, user_data); + } + g_list_free(pages); } Modified: kazehakase/trunk/src/kz-notebook.h =================================================================== --- kazehakase/trunk/src/kz-notebook.h 2009-02-14 23:11:21 UTC (rev 3693) +++ kazehakase/trunk/src/kz-notebook.h 2009-02-15 00:17:04 UTC (rev 3694) @@ -83,7 +83,7 @@ GtkWidget *kz_notebook_get_dragged_page (KzNotebook *notebook); KzEmbed *kz_notebook_get_dragged_embed (KzNotebook *notebook); GNode *kz_notebook_get_tree (KzNotebook *notebook); -void kz_notebook_foreach_page (KzNotebook *notebook, +void kz_notebook_foreach_embed (KzNotebook *notebook, GFunc func, gpointer user_data); Modified: kazehakase/trunk/src/kz-window.c =================================================================== --- kazehakase/trunk/src/kz-window.c 2009-02-14 23:11:21 UTC (rev 3693) +++ kazehakase/trunk/src/kz-window.c 2009-02-15 00:17:04 UTC (rev 3694) @@ -56,6 +56,7 @@ #include "kz-ext.h" #include "kz-statusbar.h" #include "kz-session.h" +#include "kz-bin.h" #define MAX_CLOSED_TABS 10 @@ -771,7 +772,8 @@ /* for stop/reload button updating */ kzembed = KZ_WINDOW_CURRENT_EMBED(kz); - kz_actions_set_sensitive(kz, kzembed); + if (kzembed) + kz_actions_set_sensitive(kz, kzembed); /* smart bookmark */ kz_actions_update_smartbookmarks(kz, KZ_GET_SMART_BOOKMARK); @@ -938,12 +940,26 @@ kz_notebook_close_tab(KZ_NOTEBOOK(kz->notebook), embed); } +static void +unset_each_embed_callbacks (gpointer data, gpointer user_data) +{ + kz_window_unset_embed_callbacks(KZ_WINDOW(user_data), + KZ_EMBED(data)); +} +static void +disconnect_all_embed_signals (KzWindow *kz) +{ + kz_notebook_foreach_embed(KZ_NOTEBOOK(kz->notebook), + unset_each_embed_callbacks, kz); +} + void kz_window_close_all_tab(KzWindow *kz) { g_return_if_fail(KZ_IS_WINDOW(kz)); + disconnect_all_embed_signals(kz); kz_notebook_close_all_tab(KZ_NOTEBOOK(kz->notebook)); } @@ -1033,7 +1049,7 @@ kz_window_store_state(kz); KZ_FREEZE_SESSION; - kz_notebook_close_all_tab(KZ_NOTEBOOK(kz->notebook)); + kz_window_close_all_tab(kz); KZ_THAW_SESSION; return FALSE; @@ -1123,21 +1139,13 @@ } static void -unset_each_embed_callbacks (gpointer data, gpointer user_data) -{ - kz_window_unset_embed_callbacks(KZ_WINDOW(user_data), - KZ_EMBED(data)); -} - -static void destroy (GtkObject *object) { KzWindow *kz = KZ_WINDOW(object); KzWindowPrivate *priv = KZ_WINDOW_GET_PRIVATE(kz); if (kz->notebook) { - kz_notebook_foreach_page(KZ_NOTEBOOK(kz->notebook), - unset_each_embed_callbacks, kz); + disconnect_all_embed_signals(kz); kz->notebook = NULL; } @@ -1980,7 +1988,7 @@ g_return_if_fail(tab); kz_actions_set_sensitive(kz, kzembed); - kz_actions_set_tab_sensitive(kz, kzembed); + //kz_actions_set_tab_sensitive(kz, kzembed); /* set current_position in history */ /* FIXME: KzSession should block automatically */ @@ -2143,7 +2151,7 @@ kz_window_unset_cur_embed_callbacks(kz, kzembed); kz_window_unset_embed_callbacks(kz, kzembed); - kz_notebook_close_tab(KZ_NOTEBOOK(kz->notebook), KZ_EMBED(obj)); + kz_notebook_close_tab(KZ_NOTEBOOK(kz->notebook), kzembed); kz_statusbar_set_link_text(KZ_STATUSBAR(kz->statusbar), NULL); g_signal_emit(kz, kz_window_signals[REMOVE_TAB_SIGNAL], @@ -2547,3 +2555,36 @@ kz_bookmark_folder_remove(kz->closed_tabs, last); } +void +kz_window_switch_layout_engine (KzWindow *kz, const gchar *engine_name) +{ + KzEmbed *embed = KZ_WINDOW_CURRENT_EMBED(kz); + KzTabLabel *kztab; + GtkWidget *new_embed; + GtkWidget *bin; + gint position; + + if (!embed) + return; + + new_embed = kz_embed_new(engine_name); + gtk_widget_show_all(new_embed); + + position = gtk_notebook_get_current_page(GTK_NOTEBOOK(kz->notebook)); + bin = gtk_notebook_get_nth_page(GTK_NOTEBOOK(kz->notebook), position); + kztab = kz_notebook_get_nth_tab_label(KZ_NOTEBOOK(kz->notebook), position); + + g_object_ref(embed); + kz_window_unset_cur_embed_callbacks(kz, embed); + kz_window_unset_embed_callbacks(kz, embed); + kz_window_set_cur_embed_callbacks(kz, KZ_EMBED(new_embed)); + kz_window_set_embed_callbacks(kz, KZ_EMBED(new_embed)); + kz_tab_label_set_embed(kztab, KZ_EMBED(new_embed)); + + kz_bin_change_child(KZ_BIN(bin), new_embed); + gtk_widget_show_all(bin); + + kz_embed_copy_page(embed, KZ_EMBED(new_embed)); + g_object_unref(embed); +} + Modified: kazehakase/trunk/src/kz-window.h =================================================================== --- kazehakase/trunk/src/kz-window.h 2009-02-14 23:11:21 UTC (rev 3693) +++ kazehakase/trunk/src/kz-window.h 2009-02-15 00:17:04 UTC (rev 3694) @@ -142,6 +142,8 @@ void kz_window_append_closed_tab (KzWindow *kz, KzBookmarkFolder *tab); +void kz_window_switch_layout_engine (KzWindow *kz, + const gchar *engine_name); #define KZ_WINDOW_NTH_EMBED(kz, n) \ (KZ_IS_WINDOW(kz) ? kz_notebook_get_nth_embed(KZ_NOTEBOOK(KZ_WINDOW(kz)->notebook),n) : NULL) Modified: kazehakase/trunk/src/widget/Makefile.am =================================================================== --- kazehakase/trunk/src/widget/Makefile.am 2009-02-14 23:11:21 UTC (rev 3693) +++ kazehakase/trunk/src/widget/Makefile.am 2009-02-15 00:17:04 UTC (rev 3694) @@ -16,7 +16,8 @@ kz-dlist.h \ kz-entry.h \ kz-paned.h \ - kz-thumbnail.h + kz-thumbnail.h \ + kz-bin.h enum_source_prefix = kz-widget-enum-types @@ -31,6 +32,7 @@ kz-entry.c \ kz-paned.c \ kz-thumbnail.c \ + kz-bin.c \ $(enum_sources) \ $(libkzwidget_public_h_sources) Added: kazehakase/trunk/src/widget/kz-bin.c =================================================================== --- kazehakase/trunk/src/widget/kz-bin.c (rev 0) +++ kazehakase/trunk/src/widget/kz-bin.c 2009-02-15 00:17:04 UTC (rev 3694) @@ -0,0 +1,81 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * Copyright (C) 2009 Hiroyuki Ikezoe + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "kz-bin.h" + +G_DEFINE_TYPE(KzBin, kz_bin, GTK_TYPE_BIN) + +static void size_allocate (GtkWidget *widget, + GtkAllocation *allocation); + +static void +kz_bin_class_init (KzBinClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); + + widget_class->size_allocate = size_allocate; +} + +static void +kz_bin_init (KzBin *bin) +{ +} + +GtkWidget * +kz_bin_new (void) +{ + return GTK_WIDGET(g_object_new(KZ_TYPE_BIN, NULL)); +} + +static void +size_allocate (GtkWidget *widget, GtkAllocation *allocation) +{ + GtkWidget *child; + GtkAllocation child_allocation; + + widget->allocation = *allocation; + + if (GTK_WIDGET_NO_WINDOW(widget)) + { + child_allocation.x = allocation->x + GTK_CONTAINER(widget)->border_width; + child_allocation.y = allocation->y + GTK_CONTAINER(widget)->border_width; + } + else + { + child_allocation.x = 0; + child_allocation.y = 0; + } + + child_allocation.width = MAX(allocation->width - GTK_CONTAINER(widget)->border_width * 2, 0); + child_allocation.height = MAX(allocation->height - GTK_CONTAINER(widget)->border_width * 2, 0); + + child = gtk_bin_get_child(GTK_BIN(widget)); + if (child) + gtk_widget_size_allocate(child, &child_allocation); + +} + +void +kz_bin_change_child (KzBin *bin, GtkWidget *new_child) +{ + gtk_container_remove(GTK_CONTAINER(bin), gtk_bin_get_child(GTK_BIN(bin))); + gtk_container_add(GTK_CONTAINER(bin), new_child); +} + Added: kazehakase/trunk/src/widget/kz-bin.h =================================================================== --- kazehakase/trunk/src/widget/kz-bin.h (rev 0) +++ kazehakase/trunk/src/widget/kz-bin.h 2009-02-15 00:17:04 UTC (rev 3694) @@ -0,0 +1,55 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* + * Copyright (C) 2009 Hiroyuki Ikezoe + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __KZ_BIN_H__ +#define __KZ_BIN_H__ + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define KZ_TYPE_BIN (kz_bin_get_type ()) +#define KZ_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KZ_TYPE_BIN, KzBin)) +#define KZ_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KZ_TYPE_BIN, KzBinClass)) +#define KZ_IS_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KZ_TYPE_BIN)) +#define KZ_IS_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KZ_TYPE_BIN)) +#define KZ_BIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KZ_TYPE_BIN, KzBinClass)) + +typedef struct _KzBin KzBin; +typedef struct _KzBinClass KzBinClass; + +struct _KzBin +{ + GtkBin parent; +}; + +struct _KzBinClass +{ + GtkBinClass parent_class; +}; + +GType kz_bin_get_type (void) G_GNUC_CONST; +GtkWidget *kz_bin_new (void); +void kz_bin_change_child (KzBin *bin, + GtkWidget *new_child); + +G_END_DECLS + +#endif /* __KZ_BIN_H__ */