Miaouw Library Example

Install the example.

Install the libmiaouw-dev package first. Compile this program with
gcc -o miaouwscrolling -DHILDON=0 $(pkg-config --cflags --libs miaouw gtk+-2.0 hildon-libs libosso) miaouwscrolling.c
in Maemo 3.x environment or
gcc -o miaouwscrolling $(pkg-config --cflags --libs miaouw gtk+-2.0 hildon-1 libosso) miaouwscrolling.c
in Maemo 4.x environment.

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gtk/gtk.h>
#include <ibosso.h>
#include <stdlib.h>
#if defined HILDON && HILDON == 0
#include <hildon-widgets/hildon-program.h>
#else
#include <hildon/hildon.h>
#endif

#include <miaouw/miaouw.h>

#define ROWS 30
#define COLS 15

int main(int argc, char** argv) {
	osso_context_t* osso_context;
	HildonProgram* program;
	GtkWidget* window;
	GtkWidget* scrolled_window;
	GtkWidget* event_box;
	GtkWidget* table;
	GtkWidget* widget;
	gint row, col;
	gchar buffer[1024];

	gtk_init(&argc, &argv);
	osso_context = osso_initialize("miaouw", "0.0.1", TRUE, NULL);

	program = HILDON_PROGRAM(hildon_program_get_instance());
	g_set_application_name("Miaouw");
	
	/* You can set the window title when creating a MiaouwWindow. */
	window = miaouw_window_new_with_title("Scrolling");
	hildon_program_add_window(program, HILDON_WINDOW(window));
	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

	/* The MiaouwScrolledWindow acts just like the original Gtk ScrolledWindow. */
	scrolled_window = miaouw_scrolled_window_new(NULL, NULL);
 	gtk_container_add(GTK_CONTAINER(window), scrolled_window);

	table = gtk_table_new(ROWS, COLS, TRUE);
	/* With this utility function an GtkEventBox is added between the viewport and a child widget. */
	miaouw_scrolled_window_add_with_viewport(MIAOUW_SCROLLED_WINDOW(scrolled_window), table);
	
	/* The easiest way to support D-pad is to attach scroll adjustments to it with the MiaouwWindow. */
	miaouw_window_set_vadjustment(MIAOUW_WINDOW(window),
	                              gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window)));
	miaouw_window_set_hadjustment(MIAOUW_WINDOW(window),
	                              gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(scrolled_window)));
	
	srand(time(NULL));
	for (row = 0; row < ROWS; row++) {
		for (col = 0; col < COLS; col++) {
			snprintf(buffer, 1024, "[%d %d]", col, row);
			if (rand() < RAND_MAX / 10) {
				widget = gtk_button_new_with_label(buffer);
			} else {
				widget = gtk_label_new(buffer);
				/* The MiaouwWindow can be used to directly change text widgets' font size. */
				g_signal_connect_swapped(window, "change-font-size", 
				                         G_CALLBACK(gtk_widget_modify_font), widget);
			}			
			gtk_table_attach(GTK_TABLE(table), widget, col, col + 1, row, row + 1,
			                 GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL,
					 8, 8);
		}
	}
		
	gtk_widget_show_all(window);

	gtk_main();

	return 0;
}