4 #include <glib/gi18n.h>
5 #include "tbo-window.h"
8 #include "ui-toolbar.h"
9 #include "ui-drawing.h"
10 #include "tbo-types.h"
12 static int NWINDOWS = 0;
15 tbo_window_new (GtkWidget *window, GtkWidget *dw_scroll, GtkWidget *toolarea,
16 GtkWidget *status, GtkWidget *vbox, Comic *comic)
21 tbo = malloc (sizeof (TboWindow));
23 tbo->dw_scroll = dw_scroll;
24 list = gtk_container_get_children (GTK_CONTAINER (dw_scroll));
25 tbo->drawing = GTK_WIDGET (list->data);
29 tbo->toolarea = toolarea;
36 tbo_window_free (TboWindow *tbo)
38 tbo_comic_free (tbo->comic);
39 gtk_widget_destroy (tbo->window);
46 tbo_window_set_path (TboWindow *tbo, const char *path)
50 tbo->path = malloc (255 * sizeof (char));
51 snprintf (tbo->path, 255, "%s", path);
55 tbo_window_free_cb (GtkWidget *widget, GdkEventExpose *event,
58 tbo_window_free (tbo);
65 GdkPixbuf *create_pixbuf (const gchar * filename)
69 pixbuf = gdk_pixbuf_new_from_file(filename, &error);
71 fprintf(stderr, "%s\n", error->message);
79 tbo_new_tbo (int width, int height)
85 GtkWidget *tool_paned;
94 GtkUIManager *manager;
98 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
99 gtk_window_set_default_size (GTK_WINDOW (window), width, height);
100 gtk_window_set_icon (GTK_WINDOW (window), create_pixbuf (DATA_DIR "/icon.png"));
102 // El contenedor principal
103 container = gtk_vbox_new (FALSE, 0);
104 gtk_container_add (GTK_CONTAINER (window), container);
106 comic = tbo_comic_new (_("Untitled"), width, height);
107 gtk_window_set_title (GTK_WINDOW (window), comic->title);
108 scrolled = gtk_scrolled_window_new (NULL, NULL);
109 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
110 darea = get_drawing_area (width, height);
111 gtk_container_add (GTK_CONTAINER (scrolled), darea);
113 hpaned = gtk_hpaned_new ();
114 tool_paned = gtk_vbox_new (FALSE, 0);
115 scrolled2 = gtk_scrolled_window_new (NULL, NULL);
116 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled2), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
117 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled2), tool_paned);
119 gtk_paned_set_position (GTK_PANED (hpaned), width - 200);
120 gtk_paned_pack1 (GTK_PANED (hpaned), scrolled, TRUE, FALSE);
121 gtk_paned_pack2 (GTK_PANED (hpaned), scrolled2, TRUE, FALSE);
123 status = gtk_statusbar_new ();
125 tbo = tbo_window_new (window, scrolled, tool_paned, status, container, comic);
126 tbo_window_update_status (tbo, 0, 0);
128 // ui-drawing.c (expose, motion and click)
129 darea_connect_signals (tbo);
131 g_signal_connect (window, "delete-event", G_CALLBACK (tbo_window_free_cb), tbo);
133 // Generando la barra de herramientas de la aplicacion
134 toolbar = generate_toolbar (tbo);
136 // Generando el menu de la aplicacion
137 menu = generate_menu (tbo);
139 gtk_box_pack_start (GTK_BOX (container), menu, FALSE, FALSE, 0);
140 gtk_box_pack_start (GTK_BOX (container), toolbar, FALSE, FALSE, 0);
142 gtk_container_add (GTK_CONTAINER (container), hpaned);
144 gtk_box_pack_start (GTK_BOX (container), status, FALSE, FALSE, 0);
146 gtk_widget_show_all (window);
152 tbo_window_update_status (TboWindow *tbo, int x, int y)
155 snprintf (buffer, 200, _("page: %d of %d [ %5d,%5d ] | frames: %d"),
156 tbo_comic_page_index (tbo->comic),
157 tbo_comic_len (tbo->comic),
159 tbo_page_len (tbo_comic_get_current_page (tbo->comic)));
160 gtk_statusbar_push (GTK_STATUSBAR (tbo->status), 0, buffer);
161 update_drawing (tbo);
162 update_toolbar (tbo);
166 remove_cb (GtkWidget *widget, gpointer data)
168 gtk_widget_destroy(widget);
173 tbo_empty_tool_area (TboWindow *tbo)
175 gtk_container_foreach (GTK_CONTAINER (tbo->toolarea), (GtkCallback)remove_cb, NULL);