summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-06-08 02:04:22 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-06-08 02:04:22 -0400
commite8f3b2eafc8d73b90cc50895972ea91d57ca329c (patch)
treef5c69a7baf093682048dea4382f83c686f6d0aac /main.c
parent039343b3d5d7fd05bfd0b1a530962ba546b1be37 (diff)
Toolbar
Diffstat (limited to 'main.c')
-rw-r--r--main.c94
1 files changed, 82 insertions, 12 deletions
diff --git a/main.c b/main.c
index 0e93334..bd147c6 100644
--- a/main.c
+++ b/main.c
@@ -6,16 +6,21 @@
#include <math.h>
#include "scrollarea.h"
#include "deck.h"
+#include "toolbar.h"
typedef struct
{
GladeXML * xml;
- GtkWidget * main_area;
- GtkWidget * thumbnails;
+ FooScrollArea * main_area;
+ FooScrollArea * thumbnails;
Deck * deck;
int nth_slide;
+ Toolbar * toolbar;
} App;
+#define TOOLBAR_Y_OFFSET 12
+#define TOOLBAR_X_OFFSET 12
+
static void *
get_widget (App *app, const char *name)
{
@@ -52,6 +57,39 @@ on_thumbs_viewport_size_changed (FooScrollArea *scroll_area,
}
static void
+offset_toolbar (App *app, GdkRectangle *viewport)
+{
+ GtkWidget *window = get_widget (app, "main_window");
+
+ if (!(gdk_window_get_state (window->window) & GDK_WINDOW_STATE_MAXIMIZED))
+ {
+ viewport->x += TOOLBAR_X_OFFSET;
+ viewport->y += TOOLBAR_Y_OFFSET;
+ }
+}
+
+static void
+paint_toolbar (App *app, FooScrollArea *area, cairo_t *cr)
+{
+ GdkRectangle viewport;
+
+ foo_scroll_area_get_viewport (app->main_area, &viewport);
+
+ offset_toolbar (app, &viewport);
+
+ toolbar_paint (app->toolbar, area, cr, viewport.x, viewport.y);
+}
+
+static void
+invalidate_toolbar (App *app, GdkRectangle *viewport)
+{
+ offset_toolbar (app, viewport);
+
+ toolbar_invalidate (app->toolbar,
+ app->main_area, viewport->x, viewport->y);
+}
+
+static void
on_main_paint (FooScrollArea *scroll_area,
cairo_t *cr,
GdkRectangle *extents,
@@ -59,8 +97,16 @@ on_main_paint (FooScrollArea *scroll_area,
gpointer data)
{
App *app = data;
-
+ GdkRectangle viewport;
+
+ foo_scroll_area_get_viewport (scroll_area, &viewport);
+
+ cairo_save (cr);
+
deck_paint (app->deck, scroll_area, cr);
+ paint_toolbar (app, scroll_area, cr);
+
+ cairo_restore (cr);
}
static void
@@ -92,14 +138,14 @@ on_main_viewport_size_changed (FooScrollArea *scroll_area,
foo_scroll_area_set_viewport_pos (scroll_area, 0, 0);
}
-
+
foo_scroll_area_invalidate (scroll_area);
}
static void
make_thumbnail_viewable (App *app)
{
- FooScrollArea *area = FOO_SCROLL_AREA (app->thumbnails);
+ FooScrollArea *area = app->thumbnails;
GdkRectangle viewport;
int top, height;
const int margin = 10;
@@ -123,14 +169,18 @@ on_viewport_changed (FooScrollArea *scroll_area,
GdkRectangle *old_viewport,
gpointer data)
{
+ App *app = data;
+
if (!foo_scroll_area_is_resizing (scroll_area))
{
- App *app = data;
-
app->nth_slide = deck_get_view_slide (app->deck, viewport);
make_thumbnail_viewable (app);
}
+
+ /* Invalidate toolbar */
+ invalidate_toolbar (app, old_viewport);
+ invalidate_toolbar (app, viewport);
}
static void
@@ -159,6 +209,19 @@ set_window_size (GtkWindow *window)
gtk_window_resize (window, width, height);
}
+static void
+on_state_change (GtkWidget *widget,
+ GdkEvent *event,
+ App *app)
+{
+ /* Apparently, on unmaximize we get size allocated before
+ * the window has actually changed state, so we need to
+ * invalidate here.
+ */
+
+ foo_scroll_area_invalidate (app->main_area);
+}
+
int
main (int argc, char **argv)
{
@@ -169,20 +232,21 @@ main (int argc, char **argv)
app = g_new0 (App, 1);
app->xml = glade_xml_new (GLADE_FILE, NULL, NULL);
- app->main_area = (GtkWidget *)foo_scroll_area_new();
- app->thumbnails = (GtkWidget *)foo_scroll_area_new();
+ app->main_area = foo_scroll_area_new();
+ app->thumbnails = foo_scroll_area_new();
app->deck = deck_new (on_deck_changed, app);
+ app->toolbar = toolbar_new ();
gtk_container_add (
GTK_CONTAINER (get_widget (app, "main_area_scrolled_window")),
- app->main_area);
+ GTK_WIDGET (app->main_area));
gtk_container_add (
GTK_CONTAINER (get_widget (app, "thumbnails_scrolled_window")),
- app->thumbnails);
+ GTK_WIDGET (app->thumbnails));
- foo_scroll_area_set_min_size (FOO_SCROLL_AREA (app->thumbnails), 200, -1);
+ foo_scroll_area_set_min_size (app->thumbnails, 200, -1);
g_signal_connect (app->main_area, "paint",
G_CALLBACK (on_main_paint), app);
@@ -196,9 +260,15 @@ main (int argc, char **argv)
g_signal_connect (app->thumbnails, "viewport_size_changed",
G_CALLBACK (on_thumbs_viewport_size_changed), app);
+ g_signal_connect (get_widget (app, "main_window"), "delete_event",
+ G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (get_widget (app, "main_window"), "window_state_event",
+ G_CALLBACK (on_state_change), app);
+
set_window_size (get_widget (app, "main_window"));
gtk_widget_show_all (get_widget (app, "main_window"));
+ gtk_widget_hide (get_widget (app, "toolbar1"));
gtk_main ();