/** * This file is part of maemo-examples package * * This maemo code example is licensed under a MIT-style license, * that can be found in the file called "COPYING" in the same * directory as this file. * Copyright (c) 2007-2009 Nokia Corporation. All rights reserved. */ #include #include #include /* Application UI data struct */ typedef struct _AppData AppData; struct _AppData { HildonProgram *program; HildonWindow *window; }; void ui_show_color_chooser(GtkWidget * widget, AppData * appdata) { static GdkColor color = {0, 0, 0, 0}; GtkWidget *selector; gint result; GtkColorSelection *colorsel; selector = gtk_color_selection_dialog_new("Select Color"); /* Get the color selection within the dialog */ colorsel = GTK_COLOR_SELECTION( gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG (selector))); /* Set the current selected color to selector */ gtk_color_selection_set_current_color(colorsel, &color); /* Show dialog */ result = gtk_dialog_run(GTK_DIALOG(selector)); /* Wait for user to select OK or Cancel */ switch (result) { case GTK_RESPONSE_OK: /* Get the current selected color from selector */ gtk_color_selection_get_current_color(colorsel, &color); /* Now the new color is in 'color' variable */ /* Use it however suitable for the application */ g_print("color: %d %d %d\n", color.red,color.green,color.blue); gtk_widget_destroy(selector); break; default: /* If dialog didn't return OK then it was canceled */ gtk_widget_destroy(selector); break; } } int main(int argc, char *argv[]) { /* Create needed variables */ HildonProgram *program; HildonWindow *window; GtkWidget *button; AppData *appdata; /* Initialize the GTK+ and hildon libraries. */ hildon_gtk_init(&argc, &argv); /* Create the hildon program and setup the title */ program = HILDON_PROGRAM(hildon_program_get_instance()); g_set_application_name("Hello maemo!"); /* Create HildonWindow and set it to HildonProgram */ window = HILDON_WINDOW(hildon_window_new()); hildon_program_add_window(program, window); /* Create AppData */ appdata = g_new0(AppData, 1); appdata->program = program; appdata->window = window; /* Create button and add it to main view */ button = gtk_button_new_with_label("Color Chooser"); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(ui_show_color_chooser), appdata); gtk_container_add(GTK_CONTAINER(window), button); /* Connect signal to X in the upper corner */ g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL); /* Begin the main application */ gtk_widget_show_all(GTK_WIDGET(window)); gtk_main(); /* Exit */ return 0; }