1 /*
2 * Xiphos Bible Study Tool
3 * sidebar_dialog.c - dialog for detached sidebar
4 *
5 * Copyright (C) 2000-2020 Xiphos Developer Team
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <gtk/gtk.h>
27 #include <glib/gi18n.h>
28
29 #include "gui/sidebar.h"
30 #include "gui/sidebar_dialog.h"
31 #include "gui/utilities.h"
32 #include "gui/xiphos.h"
33 #include "gui/widgets.h"
34
35 #include "main/previewer.h"
36 #include "main/settings.h"
37 #include "main/sword.h"
38 #include "main/xml.h"
39
40 #include "gui/debug_glib_null.h"
41
42 #include "xiphos_html/xiphos_html.h"
43
44 static GtkWidget *create_sidebar_dialog(void);
45 static GtkWidget *vbox_dock;
46
47 /******************************************************************************
48 * Name
49 * gui_attach_detach_sidebar
50 *
51 * Synopsis
52 * #include "sidebar_dialog.h"
53 *
54 * void gui_attach_detach_sidebar(void)
55 *
56 * Description
57 * dock/undock shortcut bar
58 *
59 *
60 * Return value
61 *
62 */
63
gui_attach_detach_sidebar(void)64 void gui_attach_detach_sidebar(void)
65 {
66 gint biblepanesize;
67
68 if (settings.docked) {
69 settings.docked = FALSE;
70 biblepanesize = settings.gs_width / 2;
71 widgets.dock_sb = create_sidebar_dialog();
72 #if GTK_CHECK_VERSION(3, 10, 0)
73 gtk_container_add(GTK_CONTAINER(vbox_dock),
74 widgets.shortcutbar);
75 #else
76 gtk_widget_reparent(widgets.shortcutbar, vbox_dock);
77 #endif
78 settings.showshortcutbar = TRUE;
79 gtk_paned_set_position(GTK_PANED(widgets.epaned), 0);
80 /*gtk_paned_set_position(GTK_PANED(widgets.hpaned),
81 biblepanesize); */
82
83 /* ugly fix until someone can make mozembed work with 'gtk_widget_reparent()' */
84 gtk_widget_destroy(sidebar.html_viewer_widget);
85 sidebar.html_viewer_widget =
86 GTK_WIDGET(XIPHOS_HTML_NEW(NULL, FALSE, SB_VIEWER_TYPE));
87 gtk_container_add(GTK_CONTAINER(sidebar.html_viewer_eventbox),
88 sidebar.html_viewer_widget);
89
90 gtk_widget_show_all(widgets.dock_sb);
91 gtk_widget_show(sidebar.html_viewer_widget);
92
93 xml_set_value("Xiphos", "misc", "sidebar_docked", "0");
94 } else {
95 settings.docked = TRUE;
96 biblepanesize =
97 (settings.gs_width - settings.sidebar_width) / 2;
98 gtk_paned_set_position(GTK_PANED(widgets.epaned),
99 settings.sidebar_width);
100 gtk_paned_set_position(GTK_PANED(widgets.hpaned),
101 biblepanesize);
102 #if GTK_CHECK_VERSION(3, 10, 0)
103 gtk_container_add(GTK_CONTAINER(widgets.epaned),
104 widgets.shortcutbar);
105 #else
106 gtk_widget_reparent(widgets.shortcutbar, widgets.epaned);
107 #endif
108
109 /* ugly fix until someone can make mozembed work with 'gtk_widget_reparent()' */
110 gtk_widget_destroy(sidebar.html_viewer_widget);
111 sidebar.html_viewer_widget =
112 GTK_WIDGET(XIPHOS_HTML_NEW(NULL, FALSE, SB_VIEWER_TYPE));
113 gtk_container_add(GTK_CONTAINER(sidebar.html_viewer_eventbox),
114 sidebar.html_viewer_widget);
115
116 gtk_widget_show(sidebar.html_viewer_widget);
117 gtk_widget_destroy(widgets.dock_sb);
118
119 xml_set_value("Xiphos", "misc", "sidebar_docked", "1");
120 }
121 main_set_previewer_widget(TRUE);
122 main_init_previewer();
123 }
124
125 /******************************************************************************
126 * Name
127 * on_dialog_destroy
128 *
129 * Synopsis
130 * #include "sidebar_dialog.h"
131 *
132 * void on_dialog_destroy(GtkObject *object, gpointer user_data)
133 *
134 * Description
135 * send the sidebar back to the main window before we
136 * destroy the dialog
137 *
138 *
139 * Return value
140 * void
141 */
142
on_dialog_destroy(GObject * object,gpointer user_data)143 static void on_dialog_destroy(GObject *object, gpointer user_data)
144 {
145 /* we need the if to prevent a loop */
146 if (!settings.docked)
147 gui_attach_detach_sidebar();
148 }
149
150 /******************************************************************************
151 * Name
152 * create_sidebar_dialog
153 *
154 * Synopsis
155 * #include "sidebar_dialog.h"
156 *
157 * GtkWidget* create_sidebar_dialog(void)
158 *
159 * Description
160 * create dialog to hold the sidebar when detached
161 *
162 *
163 * Return value
164 * GtkWidget*
165 */
166
create_sidebar_dialog(void)167 GtkWidget *create_sidebar_dialog(void)
168 {
169 GtkWidget *dlgDock;
170 gchar *title;
171
172 dlgDock = gtk_window_new(GTK_WINDOW_TOPLEVEL);
173 g_object_set_data(G_OBJECT(dlgDock), "dlgDock", dlgDock);
174 gtk_window_set_title(GTK_WINDOW(dlgDock), _("Sidebar"));
175 gtk_window_set_resizable(GTK_WINDOW(dlgDock), TRUE);
176 gtk_widget_set_size_request(dlgDock, settings.sidebar_width,
177 settings.gs_height);
178
179 UI_VBOX(vbox_dock, FALSE, 0);
180 gtk_widget_show(vbox_dock);
181 gtk_container_add(GTK_CONTAINER(dlgDock), vbox_dock);
182
183 title =
184 g_strdup_printf("%s - %s", _("Sidebar"),
185 settings.program_title);
186 gtk_window_set_title(GTK_WINDOW(dlgDock), title);
187 g_free(title);
188
189 g_signal_connect(G_OBJECT(dlgDock), "destroy",
190 G_CALLBACK(on_dialog_destroy), NULL);
191
192 return dlgDock;
193 }
194