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->drawing = gtk_bin_get_child (GTK_BIN (gtk_notebook_get_nth_page (GTK_NOTEBOOK (tbo->notebook), nth)));
90 set_frame_view (NULL);
91 set_selected_tool (NONE, tbo);
95 notebook_switch_page_cb (GtkNotebook *notebook,
96 GtkNotebookPage *page,
100 tbo_comic_set_current_page_nth (tbo->comic, page_num);
101 set_current_tab_page (tbo, FALSE);
102 update_toolbar (tbo);
103 tbo_window_update_status (tbo, 0, 0);
108 set_selected_tool (enum Tool tool, TboWindow *tbo)
110 unselect (SELECTED_TOOL, tbo);
111 SELECTED_TOOL = tool;
113 tool_signal (tool, TOOL_SELECT, tbo);
114 update_toolbar (tbo);
118 update_toolbar (TboWindow *tbo)
126 GtkAction *new_frame;
131 // Page next, prev and delete button sensitive
132 prev = gtk_action_group_get_action (ACTION_GROUP, "PrevPage");
133 next = gtk_action_group_get_action (ACTION_GROUP, "NextPage");
134 delete = gtk_action_group_get_action (ACTION_GROUP, "DelPage");
136 if (tbo_comic_page_first (tbo->comic))
137 gtk_action_set_sensitive (prev, FALSE);
139 gtk_action_set_sensitive (prev, TRUE);
141 if (tbo_comic_page_last (tbo->comic))
142 gtk_action_set_sensitive (next, FALSE);
144 gtk_action_set_sensitive (next, TRUE);
145 if (tbo_comic_len (tbo->comic) > 1)
146 gtk_action_set_sensitive (delete, TRUE);
148 gtk_action_set_sensitive (delete, FALSE);
150 // Frame view disabled in page view
151 doodle = gtk_action_group_get_action (ACTION_GROUP, "Doodle");
152 text = gtk_action_group_get_action (ACTION_GROUP, "Text");
153 new_frame = gtk_action_group_get_action (ACTION_GROUP, "NewFrame");
155 if (get_frame_view() == NULL)
157 gtk_action_set_sensitive (doodle, FALSE);
158 gtk_action_set_sensitive (text, FALSE);
159 gtk_action_set_sensitive (new_frame, TRUE);
163 gtk_action_set_sensitive (doodle, TRUE);
164 gtk_action_set_sensitive (text, TRUE);
165 gtk_action_set_sensitive (new_frame, FALSE);
170 toolbar_handler (GtkWidget *widget, gpointer data)
176 add_new_page (GtkAction *action, TboWindow *tbo)
178 Page *page = tbo_comic_new_page (tbo->comic);
179 int nth = tbo_comic_page_nth (tbo->comic, page);
180 gtk_notebook_insert_page (GTK_NOTEBOOK (tbo->notebook),
184 tbo_window_update_status (tbo, 0, 0);
185 update_toolbar (tbo);
190 del_current_page (GtkAction *action, TboWindow *tbo)
192 int nth = tbo_comic_page_index (tbo->comic);
193 tbo_comic_del_current_page (tbo->comic);
194 set_current_tab_page (tbo, TRUE);
195 gtk_notebook_remove_page (GTK_NOTEBOOK (tbo->notebook), nth);
196 tbo_window_update_status (tbo, 0, 0);
197 update_toolbar (tbo);
202 next_page (GtkAction *action, TboWindow *tbo)
204 tbo_comic_next_page (tbo->comic);
205 set_current_tab_page (tbo, TRUE);
206 update_toolbar (tbo);
207 tbo_window_update_status (tbo, 0, 0);
213 prev_page (GtkAction *action, TboWindow *tbo)
215 tbo_comic_prev_page (tbo->comic);
216 set_current_tab_page (tbo, TRUE);
217 update_toolbar (tbo);
218 tbo_window_update_status (tbo, 0, 0);
224 zoom_100 (GtkAction *action, TboWindow *tbo)
226 tbo_drawing_zoom_100 (tbo);
231 zoom_in (GtkAction *action, TboWindow *tbo)
233 tbo_drawing_zoom_in (tbo);
238 zoom_out (GtkAction *action, TboWindow *tbo)
240 tbo_drawing_zoom_out (tbo);
244 static const GtkActionEntry tbo_tools_entries [] = {
245 { "NewFileTool", GTK_STOCK_NEW, N_("_New"), "<control>N",
247 G_CALLBACK (tbo_comic_new_dialog) },
249 { "OpenFileTool", GTK_STOCK_OPEN, N_("_Open"), "<control>O",
251 G_CALLBACK (tbo_comic_open_dialog) },
253 { "SaveFileTool", GTK_STOCK_SAVE, N_("_Save"), "<control>S",
254 N_("Save current document"),
255 G_CALLBACK (tbo_comic_save_dialog) },
258 { "NewPage", GTK_STOCK_ADD, N_("New Page"), "<control>P",
260 G_CALLBACK (add_new_page) },
262 { "DelPage", GTK_STOCK_DELETE, N_("Delete Page"), "",
263 N_("Delete current page"),
264 G_CALLBACK (del_current_page) },
266 { "PrevPage", GTK_STOCK_GO_BACK, N_("Prev Page"), "",
268 G_CALLBACK (prev_page) },
270 { "NextPage", GTK_STOCK_GO_FORWARD, N_("Next Page"), "",
272 G_CALLBACK (next_page) },
275 { "Zoomin", GTK_STOCK_ZOOM_IN, N_("Zoom in"), "",
277 G_CALLBACK (zoom_in) },
278 { "Zoom100", GTK_STOCK_ZOOM_100, N_("Zoom 1:1"), "",
280 G_CALLBACK (zoom_100) },
281 { "Zoomout", GTK_STOCK_ZOOM_OUT, N_("Zoom out"), "",
283 G_CALLBACK (zoom_out) },
286 static const GtkToggleActionEntry tbo_tools_toogle_entries [] = {
288 { "NewFrame", TBO_STOCK_FRAME, N_("New _Frame"), "<control>F",
290 G_CALLBACK (select_tool), FALSE },
292 { "Selector", TBO_STOCK_SELECTOR, N_("Selector"), "",
294 G_CALLBACK (select_tool), FALSE },
297 { "Doodle", TBO_STOCK_DOODLE, N_("Doodle"), "",
299 G_CALLBACK (select_tool), FALSE },
300 { "Text", TBO_STOCK_TEXT, N_("Text"), "",
302 G_CALLBACK (select_tool), FALSE },
305 static const tool_and_action tools_actions [] = {
307 {SELECTOR, "Selector"},
313 set_selected_tool_and_action (enum Tool tool, TboWindow *tbo)
315 GtkToggleAction *action;
316 enum Tool action_tool;
320 GtkToggleActionEntry entry;
322 for (i=0; i<G_N_ELEMENTS (tools_actions); i++)
324 if (tool == tools_actions[i].tool)
326 name = (gchar *) tools_actions[i].action;
331 action = (GtkToggleAction *) gtk_action_group_get_action (ACTION_GROUP, name);
332 if (gtk_action_is_sensitive (GTK_ACTION (action)))
333 gtk_toggle_action_set_active (action, TRUE);
337 unselect (enum Tool tool, TboWindow *tbo)
340 GtkToggleAction *action;
342 for (i=0; i<G_N_ELEMENTS (tools_actions); i++)
344 if (tools_actions[i].tool == tool)
346 action = (GtkToggleAction *) gtk_action_group_get_action (ACTION_GROUP,
347 tools_actions[i].action);
349 gtk_toggle_action_set_active (action, FALSE);
353 tool_signal (tool, TOOL_UNSELECT, tbo);
357 select_tool (GtkAction *action, TboWindow *tbo)
359 GtkToggleAction *toggle_action;
364 toggle_action = (GtkToggleAction *) action;
365 name = gtk_action_get_name (action);
368 for (i=0; i<G_N_ELEMENTS (tools_actions); i++)
370 if (strcmp (tools_actions[i].action, name) == 0)
372 tool = tools_actions[i].tool;
377 if (gtk_toggle_action_get_active (toggle_action))
378 set_selected_tool (tool, tbo);
380 set_selected_tool (NONE, tbo);
381 tbo_window_update_status (tbo, 0, 0);
385 GtkWidget *generate_toolbar (TboWindow *window){
387 GtkUIManager *manager;
388 GError *error = NULL;
390 manager = gtk_ui_manager_new ();
391 gtk_ui_manager_add_ui_from_file (manager, DATA_DIR "/ui/tbo-toolbar-ui.xml", &error);
394 g_warning ("Could not merge tbo-toolbar-ui.xml: %s", error->message);
395 g_error_free (error);
398 ACTION_GROUP = gtk_action_group_new ("ToolsActions");
399 gtk_action_group_set_translation_domain (ACTION_GROUP, NULL);
400 gtk_action_group_add_actions (ACTION_GROUP, tbo_tools_entries,
401 G_N_ELEMENTS (tbo_tools_entries), window);
402 gtk_action_group_add_toggle_actions (ACTION_GROUP, tbo_tools_toogle_entries,
403 G_N_ELEMENTS (tbo_tools_toogle_entries), window);
405 gtk_ui_manager_insert_action_group (manager, ACTION_GROUP, 0);
407 toolbar = gtk_ui_manager_get_widget (manager, "/toolbar");
409 update_toolbar (window);
415 tool_signal (enum Tool tool, enum ToolSignal signal, gpointer data)
418 ToolStruct *toolstruct = NULL;
421 for (i=0; i<G_N_ELEMENTS (TOOLS); i++)
423 if (tool == TOOLS[i].tool)
425 toolstruct = &TOOLS[i];
435 toolstruct->tool_on_select(data);
438 toolstruct->tool_on_unselect(data);
442 toolstruct->tool_on_move (pdata[0], pdata[1], pdata[2]);
446 toolstruct->tool_on_click (pdata[0], pdata[1], pdata[2]);
450 toolstruct->tool_on_release (pdata[0], pdata[1], pdata[2]);
454 toolstruct->tool_on_key (pdata[0], pdata[1], pdata[2]);
457 toolstruct->tool_drawing (data);