4 #include <glib/gi18n.h>
6 #include "ui-toolbar.h"
8 #include "comic-new-dialog.h"
9 #include "comic-saveas-dialog.h"
10 #include "comic-open-dialog.h"
11 #include "tbo-window.h"
13 #include "custom-stock.h"
14 #include "ui-drawing.h"
16 #include "frame-tool.h"
17 #include "selector-tool.h"
18 #include "doodle-tool.h"
19 #include "text-tool.h"
21 static int SELECTED_TOOL = NONE;
22 static GtkActionGroup *ACTION_GROUP = NULL;
24 static ToolStruct TOOLS[] =
28 frame_tool_on_unselect,
31 frame_tool_on_release,
36 selector_tool_on_select,
37 selector_tool_on_unselect,
38 selector_tool_on_move,
39 selector_tool_on_click,
40 selector_tool_on_release,
42 selector_tool_drawing},
45 doodle_tool_on_select,
46 doodle_tool_on_unselect,
49 doodle_tool_on_release,
55 text_tool_on_unselect,
70 void unselect (enum Tool tool, TboWindow *tbo);
71 gboolean select_tool (GtkAction *action, TboWindow *tbo);
72 void update_toolbar (TboWindow *tbo);
82 set_current_tab_page (TboWindow *tbo, gboolean setit)
86 nth = tbo_comic_page_index (tbo->comic);
88 gtk_notebook_set_current_page (GTK_NOTEBOOK (tbo->notebook), nth);
89 tbo->dw_scroll = gtk_notebook_get_nth_page (GTK_NOTEBOOK (tbo->notebook), nth);
90 tbo->drawing = gtk_bin_get_child (GTK_BIN (tbo->dw_scroll));
91 set_frame_view (NULL);
92 set_selected_tool (NONE, tbo);
96 notebook_switch_page_cb (GtkNotebook *notebook,
97 GtkNotebookPage *page,
101 tbo_comic_set_current_page_nth (tbo->comic, page_num);
102 set_current_tab_page (tbo, FALSE);
103 update_toolbar (tbo);
104 tbo_window_update_status (tbo, 0, 0);
109 set_selected_tool (enum Tool tool, TboWindow *tbo)
111 unselect (SELECTED_TOOL, tbo);
112 SELECTED_TOOL = tool;
114 tool_signal (tool, TOOL_SELECT, tbo);
115 update_toolbar (tbo);
119 update_toolbar (TboWindow *tbo)
127 GtkAction *new_frame;
132 // Page next, prev and delete button sensitive
133 prev = gtk_action_group_get_action (ACTION_GROUP, "PrevPage");
134 next = gtk_action_group_get_action (ACTION_GROUP, "NextPage");
135 delete = gtk_action_group_get_action (ACTION_GROUP, "DelPage");
137 if (tbo_comic_page_first (tbo->comic))
138 gtk_action_set_sensitive (prev, FALSE);
140 gtk_action_set_sensitive (prev, TRUE);
142 if (tbo_comic_page_last (tbo->comic))
143 gtk_action_set_sensitive (next, FALSE);
145 gtk_action_set_sensitive (next, TRUE);
146 if (tbo_comic_len (tbo->comic) > 1)
147 gtk_action_set_sensitive (delete, TRUE);
149 gtk_action_set_sensitive (delete, FALSE);
151 // Frame view disabled in page view
152 doodle = gtk_action_group_get_action (ACTION_GROUP, "Doodle");
153 text = gtk_action_group_get_action (ACTION_GROUP, "Text");
154 new_frame = gtk_action_group_get_action (ACTION_GROUP, "NewFrame");
156 if (get_frame_view() == NULL)
158 gtk_action_set_sensitive (doodle, FALSE);
159 gtk_action_set_sensitive (text, FALSE);
160 gtk_action_set_sensitive (new_frame, TRUE);
164 gtk_action_set_sensitive (doodle, TRUE);
165 gtk_action_set_sensitive (text, TRUE);
166 gtk_action_set_sensitive (new_frame, FALSE);
171 toolbar_handler (GtkWidget *widget, gpointer data)
177 add_new_page (GtkAction *action, TboWindow *tbo)
179 Page *page = tbo_comic_new_page (tbo->comic);
180 int nth = tbo_comic_page_nth (tbo->comic, page);
181 gtk_notebook_insert_page (GTK_NOTEBOOK (tbo->notebook),
185 tbo_window_update_status (tbo, 0, 0);
186 update_toolbar (tbo);
191 del_current_page (GtkAction *action, TboWindow *tbo)
193 int nth = tbo_comic_page_index (tbo->comic);
194 tbo_comic_del_current_page (tbo->comic);
195 set_current_tab_page (tbo, TRUE);
196 gtk_notebook_remove_page (GTK_NOTEBOOK (tbo->notebook), nth);
197 tbo_window_update_status (tbo, 0, 0);
198 update_toolbar (tbo);
203 next_page (GtkAction *action, TboWindow *tbo)
205 tbo_comic_next_page (tbo->comic);
206 set_current_tab_page (tbo, TRUE);
207 update_toolbar (tbo);
208 tbo_window_update_status (tbo, 0, 0);
214 prev_page (GtkAction *action, TboWindow *tbo)
216 tbo_comic_prev_page (tbo->comic);
217 set_current_tab_page (tbo, TRUE);
218 update_toolbar (tbo);
219 tbo_window_update_status (tbo, 0, 0);
225 zoom_100 (GtkAction *action, TboWindow *tbo)
227 tbo_drawing_zoom_100 (tbo);
232 zoom_in (GtkAction *action, TboWindow *tbo)
234 tbo_drawing_zoom_in (tbo);
239 zoom_out (GtkAction *action, TboWindow *tbo)
241 tbo_drawing_zoom_out (tbo);
245 static const GtkActionEntry tbo_tools_entries [] = {
246 { "NewFileTool", GTK_STOCK_NEW, N_("_New"), "<control>N",
248 G_CALLBACK (tbo_comic_new_dialog) },
250 { "OpenFileTool", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
252 G_CALLBACK (tbo_comic_open_dialog) },
254 { "SaveFileTool", GTK_STOCK_SAVE, N_("_Save"), "<control>S",
255 N_("Save current document"),
256 G_CALLBACK (tbo_comic_save_dialog) },
259 { "NewPage", GTK_STOCK_ADD, N_("New Page"), "<control>P",
261 G_CALLBACK (add_new_page) },
263 { "DelPage", GTK_STOCK_DELETE, N_("Delete Page"), "",
264 N_("Delete current page"),
265 G_CALLBACK (del_current_page) },
267 { "PrevPage", GTK_STOCK_GO_BACK, N_("Prev Page"), "",
269 G_CALLBACK (prev_page) },
271 { "NextPage", GTK_STOCK_GO_FORWARD, N_("Next Page"), "",
273 G_CALLBACK (next_page) },
276 { "Zoomin", GTK_STOCK_ZOOM_IN, N_("Zoom in"), "",
278 G_CALLBACK (zoom_in) },
279 { "Zoom100", GTK_STOCK_ZOOM_100, N_("Zoom 1:1"), "",
281 G_CALLBACK (zoom_100) },
282 { "Zoomout", GTK_STOCK_ZOOM_OUT, N_("Zoom out"), "",
284 G_CALLBACK (zoom_out) },
287 static const GtkToggleActionEntry tbo_tools_toogle_entries [] = {
289 { "NewFrame", TBO_STOCK_FRAME, N_("New _Frame"), "<control>F",
291 G_CALLBACK (select_tool), FALSE },
293 { "Selector", TBO_STOCK_SELECTOR, N_("Selector"), "",
295 G_CALLBACK (select_tool), FALSE },
298 { "Doodle", TBO_STOCK_DOODLE, N_("Doodle"), "",
300 G_CALLBACK (select_tool), FALSE },
301 { "Text", TBO_STOCK_TEXT, N_("Text"), "",
303 G_CALLBACK (select_tool), FALSE },
306 static const tool_and_action tools_actions [] = {
308 {SELECTOR, "Selector"},
314 set_selected_tool_and_action (enum Tool tool, TboWindow *tbo)
316 GtkToggleAction *action;
317 enum Tool action_tool;
321 GtkToggleActionEntry entry;
323 for (i=0; i<G_N_ELEMENTS (tools_actions); i++)
325 if (tool == tools_actions[i].tool)
327 name = (gchar *) tools_actions[i].action;
332 action = (GtkToggleAction *) gtk_action_group_get_action (ACTION_GROUP, name);
333 if (gtk_action_is_sensitive (GTK_ACTION (action)))
334 gtk_toggle_action_set_active (action, TRUE);
338 unselect (enum Tool tool, TboWindow *tbo)
341 GtkToggleAction *action;
343 for (i=0; i<G_N_ELEMENTS (tools_actions); i++)
345 if (tools_actions[i].tool == tool)
347 action = (GtkToggleAction *) gtk_action_group_get_action (ACTION_GROUP,
348 tools_actions[i].action);
350 gtk_toggle_action_set_active (action, FALSE);
354 tool_signal (tool, TOOL_UNSELECT, tbo);
358 select_tool (GtkAction *action, TboWindow *tbo)
360 GtkToggleAction *toggle_action;
365 toggle_action = (GtkToggleAction *) action;
366 name = gtk_action_get_name (action);
369 for (i=0; i<G_N_ELEMENTS (tools_actions); i++)
371 if (strcmp (tools_actions[i].action, name) == 0)
373 tool = tools_actions[i].tool;
378 if (gtk_toggle_action_get_active (toggle_action))
379 set_selected_tool (tool, tbo);
381 set_selected_tool (NONE, tbo);
382 tbo_window_update_status (tbo, 0, 0);
386 GtkWidget *generate_toolbar (TboWindow *window){
388 GtkUIManager *manager;
389 GError *error = NULL;
391 manager = gtk_ui_manager_new ();
392 gtk_ui_manager_add_ui_from_file (manager, DATA_DIR "/ui/tbo-toolbar-ui.xml", &error);
395 g_warning ("Could not merge tbo-toolbar-ui.xml: %s", error->message);
396 g_error_free (error);
399 ACTION_GROUP = gtk_action_group_new ("ToolsActions");
400 gtk_action_group_set_translation_domain (ACTION_GROUP, NULL);
401 gtk_action_group_add_actions (ACTION_GROUP, tbo_tools_entries,
402 G_N_ELEMENTS (tbo_tools_entries), window);
403 gtk_action_group_add_toggle_actions (ACTION_GROUP, tbo_tools_toogle_entries,
404 G_N_ELEMENTS (tbo_tools_toogle_entries), window);
406 gtk_ui_manager_insert_action_group (manager, ACTION_GROUP, 0);
408 toolbar = gtk_ui_manager_get_widget (manager, "/toolbar");
410 update_toolbar (window);
416 tool_signal (enum Tool tool, enum ToolSignal signal, gpointer data)
419 ToolStruct *toolstruct = NULL;
422 for (i=0; i<G_N_ELEMENTS (TOOLS); i++)
424 if (tool == TOOLS[i].tool)
426 toolstruct = &TOOLS[i];
436 toolstruct->tool_on_select(data);
439 toolstruct->tool_on_unselect(data);
443 toolstruct->tool_on_move (pdata[0], pdata[1], pdata[2]);
447 toolstruct->tool_on_click (pdata[0], pdata[1], pdata[2]);
451 toolstruct->tool_on_release (pdata[0], pdata[1], pdata[2]);
455 toolstruct->tool_on_key (pdata[0], pdata[1], pdata[2]);
458 toolstruct->tool_drawing (data);