diff options
141 files changed, 196 insertions, 38732 deletions
diff --git a/MIGRATION b/MIGRATION new file mode 100644 index 0000000..88ca2fa --- /dev/null +++ b/MIGRATION @@ -0,0 +1,170 @@ +Standard GTK+ 2 to GTK+ 3 migration guide: +http://developer.gnome.org/gtk3/3.3/ch25s02.html + + +Following is an extract of depreciation comments from code that was removed +in libhildon 3.0. It should guide you how to migrate deprecated widgets. + + * #HildonBreadCrumbTrail is deprecated since hildon 2.2. You should instead use + * #HildonStackableWindow to represent hierarchical structure in + * applications. + + * #HildonBreadCrumb is deprecated since hildon 2.2. You should instead use + * #HildonStackableWindow to represent hierarchical structure in + * applications. + + * #HildonCalendarPopup has been deprecated since Hildon 2.2 and should not + * be used in newly written code. + * See <link linkend="hildon-migrating-date-widgets">Migrating Date Widgets</link> + * section to know how to migrate this deprecated widget. + + * #HildonCalendar has been deprecated since Hildon 2.2 + * See <link linkend="hildon-migrating-date-widgets">Migrating Date Widgets</link> + * section to know how to migrate this deprecated widget. + + * #HildonControlbar has been deprecated since Hildon 2.2 + * See <link linkend="hildon-migrating-control-bar">Migrating Control Bars</link> + * section to know how to migrate this deprecated widget. + + * #HildonDateEditor has been deprecated since Hildon 2.2 and should + * not be used in newly written code. Use #HildonDateSelector instead. See + * <link linkend="hildon-migrating-date-widgets">Migrating Date Widgets</link> + * section to know how to migrate this deprecated widget. + + * As of hildon 2.2, #HildonDialog has been deprecated in favor of #GtkDialog. + * #HildonDialog has been deprecated since Hildon 2.2 and should not + * be used in newly written code. See + * <link linkend="hildon-migrating-hildon-dialogs">Migrating Hildon Dialogs</link> + * section to know how to migrate this deprecated widget. + + * HildonFontSelectionDialog:preview-text: + * Deprecated: this property is unused since hildon 2.2 + + * hildon_helper_set_insensitive_message: + * Deprecated: As of hildon 2.2, it is strongly discouraged to use insensitive messages. + + * hildon_helper_set_insensitive_messagef: + * Deprecated: As of hildon 2.2, it is strongly discouraged to use insensitive messages. + + * #HildonHVolumeBar has been deprecated since Hildon 2.2 + * See <link linkend="hildon-migrating-volume-bar">Migrating Volume Bars</link> + * section to know how to migrate this deprecated widget. + + * HildonNote:icon: + * Deprecated: Since 2.2 + + * HildonNote:stock-icon: + * Deprecated: Since 2.2 + + * hildon_note_new_confirmation_with_icon_name: + * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set + * with this function will be ignored. Use hildon_note_new_confirmation() instead. + + * hildon_note_new_information_with_icon_name: + * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set + * with this function will be ignored. Use hildon_note_new_information() + + * #HildonNumberEditor has been deprecated since Hildon 2.2 + * See <link linkend="hildon-migrating-number-widgets">Migrating Number Widgets</link> + * section to know how to migrate this deprecated widget. + + * HildonPannableArea:size-request-policy: + * Deprecated: since 2.2 + + * hildon_pannable_area_get_size_request_policy: + * Deprecated: See hildon_pannable_area_set_size_request_policy() + + * hildon_pannable_area_set_size_request_policy: + * Deprecated: This method and the policy request is deprecated, DO + * NOT use it in future code, the only policy properly supported in + * gtk+ nowadays is the minimum size. Use gtk_window_set_default_size() + * or gtk_window_set_geometry_hints() with the proper size in your case + * to define the height of your dialogs. + + * hildon_program_pop_window_stack: + * Deprecated: Use hildon_window_stack_pop() instead + + * hildon_program_peek_window_stack: + * Deprecated: Use hildon_window_stack_peek() instead + + * hildon_program_go_to_root_window: + * Deprecated: See #HildonWindowStack + + * #HildonRangeEditor has been deprecated since Hildon 2.2 and should not + * be used in newly written code. See + * <link linkend="hildon-migrating-number-widgets">Migrating Number Widgets</link> + * section to know how to migrate this deprecated widget. + + * #HildonSeekbar has been deprecated since hildon 2.2. Use #GtkScale + * instead. See hildon_gtk_hscale_new() and hildon_gtk_vscale_new(). + + * #HildonSortDialog has been deprecated since Hildon 2.2 + * See <link linkend="hildon-migrating-sort-dialogs">Migrating Sort Dialogs</link> + * section to know how to migrate this deprecated widget. + + * hildon_stackable_window_set_main_menu: + * Deprecated: Hildon 2.2: use hildon_window_set_app_menu() + + * hildon_text_view_set_buffer: + * Deprecated: use gtk_text_view_set_buffer() instead + + * hildon_text_view_get_buffer: + * Deprecated: use gtk_text_view_get_buffer() instead + + * hildon_text_view_set_placeholder: + * Deprecated: use hildon_gtk_text_view_set_placeholder_text() instead + + * #HildonTimeEditor has been deprecated since Hildon 2.2 and should not + * be used in newly written code. See + * <link linkend="hildon-migrating-time-widgets">Migrating Time Widgets</link> + * section to know how to migrate this deprecated widget. + + * #HildonTimePicker has been deprecated since Hildon 2.2 and should not + * be used in newly written code. See + * <link linkend="hildon-migrating-time-widgets">Migrating Time Widgets</link> + * section to know how to migrate this deprecated widget. + + * HildonTouchSelectorEntry:text-column: + * This property is deprecated. Use HildonTouchSelectorColumn:text-column + * instead. Use hildon_touch_selector_entry_set_text_column() and + * hildon_touch_selector_entry_get_text_column() to manage it. + * Deprecated: use HildonTouchSelectorColumn:text-column instead + + * hildon_touch_selector_set_column_attributes: + * Deprecated: #HildonTouchSelectorColumn implements #GtkCellLayout, use this + * interface instead. See + * hildon_touch_selector_get_column(). + + * #HildonVolumebarRange has been deprecated since Hildon 2.2 and should not + * be used in newly written code. See + * <link linkend="hildon-migrating-volume-bar">Migrating Volume Bars</link> + * section to know how to migrate this deprecated widget. + + * #HildonVolumebar has been deprecated since Hildon 2.2 and should not + * be used in newly written code. See + * <link linkend="hildon-migrating-volume-bar">Migrating Volume Bars</link> + * section to know how to migrate this deprecated widget. + + * hildon_volumebar_set_range_insensitive_message: + * Deprecated: As of hildon 2.2, it is strongly discouraged to use insensitive messages. + + * hildon_volumebar_set_range_insensitive_messagef: + * Deprecated: As of hildon 2.2, it is strongly discouraged to use insensitive messages. + + * #HildonVVolumebar has been deprecated since Hildon 2.2 and should not + * be used in newly written code. See + * <link linkend="hildon-migrating-volume-bar">Migrating Volume Bars</link> + * section to know how to migrate this deprecated widget. + + * #HildonWeekdayPicker has been deprecated since Hildon 2.2 and should not + * be used in newly written code. See + * <link linkend="hildon-migrating-date-widgets">Migrating Date Widgets</link> + * section to know how to migrate this deprecated widget. + + * hildon_window_get_menu: + * Deprecated: In Hildon 2.2 this function has been renamed to + * hildon_window_get_main_menu() for consistency + + * hildon_window_set_menu: + * Deprecated: Hildon 2.2: use hildon_window_set_main_menu() + diff --git a/configure.ac b/configure.ac index ff5066e..116d6b0 100644 --- a/configure.ac +++ b/configure.ac @@ -163,18 +163,6 @@ else FATAL_CFLAGS="" fi -# disable deprecated symbols -AC_ARG_ENABLE(deprecated, - [AC_HELP_STRING([--enable-deprecated], - [enable use of deprecated symbols [default=yes]])],, - [enable_deprecated="yes"]) - -if test x$enable_deprecated = xno; then - DISABLE_DEPRECATED="-DHILDON_DISABLE_DEPRECATED" -fi - -AM_CONDITIONAL([HILDON_DISABLE_DEPRECATED], test "x$enable_deprecated" = "xno") - # Check support (c unit test) PKG_CHECK_MODULES(CHECK, check , [BUILD_TESTS="yes"], [BUILD_TESTS="no"]) AM_CONDITIONAL(BUILD_TESTS, test "x$BUILD_TESTS" = "xyes") @@ -182,8 +170,8 @@ AM_CONDITIONAL(BUILD_TESTS, test "x$BUILD_TESTS" = "xyes") CFLAGS="$CFLAGS ${ASSERT_CFLAGS} ${DEBUG_CFLAGS} -Wall -Wmissing-prototypes -Wmissing-declarations -Wno-format ${FATAL_CFLAGS}" # -Wno-format due to way translation string are done -### disable deprecated symbols and enable MAEMO platform extensions -EXTRA_CFLAGS="$DISABLE_DEPRECATED $MAEMO_CHANGES $MAEMO_GTK" +### enable MAEMO platform extensions +EXTRA_CFLAGS="$MAEMO_CHANGES $MAEMO_GTK" AC_SUBST(EXTRA_CFLAGS) # HILDON_OBJ_* @@ -217,7 +205,6 @@ Configuration: - Version............: ${VERSION} - Api................: ${PACKAGE}-${API_VERSION_MAJOR} - Compiler...........: ${CC} -- Enable deprecated..: ${enable_deprecated} - gtk-doc support....: ${enable_gtk_doc} - Build examples.....: ${BUILD_EXAMPLES} - Build with asserts.: ${BUILD_WITH_ASSERTS} diff --git a/examples/Makefile.am b/examples/Makefile.am index 103c9d5..663dbdc 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -43,48 +43,12 @@ EXAMPLES = hildon-window-example \ hildon-touch-selector-entry-example \ hildon-progress-indicator-example \ hildon-remote-texture-example \ - hildon-gtk-window-take-screenshot-sync -if USE_MAEMO_GTK -MAEMO_GTK_EXAMPLES = hildon-pannable-area-touch-list-example \ + hildon-gtk-window-take-screenshot-sync \ + hildon-pannable-area-touch-list-example \ hildon-pannable-area-touch-grid-example -else -MAEMO_GTK_EXAMPLES = -endif -DEPRECATED_EXAMPLES = hildon-weekday-picker-example \ - hildon-sort-dialog-example \ - hildon-controlbar-example \ - hildon-time-picker-example \ - hildon-color-chooser-example \ - hildon-color-button-example \ - hildon-login-dialog-example \ - hildon-time-editor-example \ - hildon-get-password-dialog-example \ - hildon-set-password-dialog-example \ - hildon-vvolumebar-example \ - hildon-code-dialog-example \ - hildon-hvolumebar-example \ - hildon-hvolumebar-insensitive-example \ - hildon-hvolumebar-insensitive-map-example \ - hildon-number-editor-example \ - hildon-color-pop-example \ - hildon-thumb-scrollbar-example \ - hildon-date-editor-example \ - hildon-bread-crumb-trail-example \ - hildon-seekbar-example \ - hildon-toolbar-seekbar-example \ - hildon-hvolumebar-timer-example \ - hildon-insensitive-example - - -if HILDON_DISABLE_DEPRECATED -noinst_PROGRAMS = $(EXAMPLES) \ - $(MAEMO_GTK_EXAMPLES) -else -noinst_PROGRAMS = $(EXAMPLES) \ - $(DEPRECATED_EXAMPLES) \ - $(MAEMO_GTK_EXAMPLES) -endif + +noinst_PROGRAMS = $(EXAMPLES) # Hildon window hildon_window_example_LDADD = $(HILDON_OBJ_LIBS) @@ -99,10 +63,10 @@ hildon_stackable_window_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ hildon_stackable_window_example_SOURCES = hildon-stackable-window-example.c # Hildon logical color -hildon_logical_color_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_logical_color_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_logical_color_example_SOURCES = hildon-logical-color-example.c +hildon_logical_color_example_LDADD = $(HILDON_OBJ_LIBS) +hildon_logical_color_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ + $(EXTRA_CFLAGS) +hildon_logical_color_example_SOURCES = hildon-logical-color-example.c # Hildon wizard dialog hildon_wizard_dialog_example_LDADD = $(HILDON_OBJ_LIBS) @@ -134,18 +98,6 @@ hildon_edit_toolbar_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) hildon_edit_toolbar_example_SOURCES = hildon-edit-toolbar-example.c -# Hildon seekbar -hildon_seekbar_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_seekbar_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_seekbar_example_SOURCES = hildon-seekbar-example.c - -# Hildon toolbar seekbar -hildon_toolbar_seekbar_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_toolbar_seekbar_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_toolbar_seekbar_example_SOURCES = hildon-toolbar-seekbar-example.c - # Hildon finger hildon_finger_example_LDADD = $(HILDON_OBJ_LIBS) hildon_finger_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ @@ -176,97 +128,19 @@ hildon_caption_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) hildon_caption_example_SOURCES = hildon-caption-example.c -# Hildon weekday picker -hildon_weekday_picker_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_weekday_picker_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_weekday_picker_example_SOURCES = hildon-weekday-picker-example.c - -# Hildon time picker -hildon_time_picker_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_time_picker_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_time_picker_example_SOURCES = hildon-time-picker-example.c - -# Hildon time editor -hildon_time_editor_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_time_editor_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_time_editor_example_SOURCES = hildon-time-editor-example.c - -# Hildon sort dialog -hildon_sort_dialog_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_sort_dialog_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_sort_dialog_example_SOURCES = hildon-sort-dialog-example.c - -# Hildon control bar -hildon_controlbar_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_controlbar_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_controlbar_example_SOURCES = hildon-controlbar-example.c - # Hildon note example hildon_note_example_LDADD = $(HILDON_OBJ_LIBS) hildon_note_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) hildon_note_example_SOURCES = hildon-note-example.c -# Hildon color chppser example -hildon_color_chooser_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_color_chooser_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_color_chooser_example_SOURCES = hildon-color-chooser-example.c - -# Hildon color button example -hildon_color_button_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_color_button_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_color_button_example_SOURCES = hildon-color-button-example.c - -# Hildon color pop example -hildon_color_pop_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_color_pop_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_color_pop_example_SOURCES = hildon-color-pop-example.c - -# Hildon color button example -hildon_login_dialog_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_login_dialog_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_login_dialog_example_SOURCES = hildon-login-dialog-example.c - -# HIldon window +# Hildon window hildon_icon_sizes_example_LDADD = $(HILDON_OBJ_LIBS) hildon_icon_sizes_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) hildon_icon_sizes_example_SOURCES = hildon-icon-sizes-example.c -# HIldon insensitive example -hildon_insensitive_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_insensitive_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_insensitive_example_SOURCES = hildon-insensitive-example.c - -# HIldon insensitive map example -hildon_hvolumebar_insensitive_map_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_hvolumebar_insensitive_map_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_hvolumebar_insensitive_map_example_SOURCES = hildon-hvolumebar-insensitive-map-example.c - -# HIldon get password dialog example -hildon_get_password_dialog_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_get_password_dialog_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_get_password_dialog_example_SOURCES = hildon-get-password-dialog-example.c - -# HIldon set password dialog example -hildon_set_password_dialog_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_set_password_dialog_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_set_password_dialog_example_SOURCES = hildon-set-password-dialog-example.c - -# HIldon window menu example +# Hildon window menu example hildon_window_menu_example_LDADD = $(HILDON_OBJ_LIBS) hildon_window_menu_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) @@ -278,78 +152,24 @@ hildon_window_cmn_menu_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) hildon_window_cmn_menu_example_SOURCES = hildon-window-cmn-menu-example.c -# Hildon vvolume bar example -hildon_vvolumebar_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_vvolumebar_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_vvolumebar_example_SOURCES = hildon-vvolumebar-example.c - -# Hildon hvolume bar example -hildon_hvolumebar_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_hvolumebar_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_hvolumebar_example_SOURCES = hildon-hvolumebar-example.c - -# Hildon hvolume bar insensitive example -hildon_hvolumebar_insensitive_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_hvolumebar_insensitive_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_hvolumebar_insensitive_example_SOURCES = hildon-hvolumebar-insensitive-example.c - # Hildon toolbar example hildon_toolbar_example_LDADD = $(HILDON_OBJ_LIBS) hildon_toolbar_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) hildon_toolbar_example_SOURCES = hildon-toolbar-example.c -# Hildon lock code dialog example -hildon_code_dialog_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_code_dialog_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_code_dialog_example_SOURCES = hildon-code-dialog-example.c - # Hildon lookup example hildon_lookup_example_LDADD = $(HILDON_OBJ_LIBS) hildon_lookup_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) hildon_lookup_example_SOURCES = hildon-lookup-example.c -# Hildon number editor -hildon_number_editor_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_number_editor_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_number_editor_example_SOURCES = hildon-number-editor-example.c - # Hildon scrolled window hildon_scrolled_window_example_LDADD = $(HILDON_OBJ_LIBS) hildon_scrolled_window_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ $(EXTRA_CFLAGS) hildon_scrolled_window_example_SOURCES = hildon-scrolled-window-example.c -# Hildon thumb scrollbar example -hildon_thumb_scrollbar_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_thumb_scrollbar_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_thumb_scrollbar_example_SOURCES = hildon-thumb-scrollbar-example.c - -# Hildon date editor example -hildon_date_editor_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_date_editor_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_date_editor_example_SOURCES = hildon-date-editor-example.c - -# Hildon bread crumb trail example -hildon_bread_crumb_trail_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_bread_crumb_trail_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_bread_crumb_trail_example_SOURCES = hildon-bread-crumb-trail-example.c - -# Hildon volumebar timer example -hildon_hvolumebar_timer_example_LDADD = $(HILDON_OBJ_LIBS) -hildon_hvolumebar_timer_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ - $(EXTRA_CFLAGS) -hildon_hvolumebar_timer_example_SOURCES = hildon-hvolumebar-timer-example.c - # Hildon pannable area tree view example hildon_pannable_area_tree_view_example_LDADD = $(HILDON_OBJ_LIBS) hildon_pannable_area_tree_view_example_CFLAGS = $(HILDON_OBJ_CFLAGS) \ diff --git a/examples/hildon-banner-example.c b/examples/hildon-banner-example.c index 1d0b5aa..26f082b 100644 --- a/examples/hildon-banner-example.c +++ b/examples/hildon-banner-example.c @@ -85,26 +85,6 @@ custom_widget_new (void) return area; } -#ifndef HILDON_DISABLE_DEPRECATED - -static gboolean -on_animation_idle (GtkWidget *banner) -{ - gtk_widget_destroy (banner); - g_object_unref (banner); - return FALSE; -} - -static gboolean -on_progress_idle (GtkWidget *banner) -{ - gtk_widget_destroy (banner); - g_object_unref (banner); - return FALSE; -} - -#endif - static void on_information_clicked (GtkWidget *widget) { @@ -112,26 +92,6 @@ on_information_clicked (GtkWidget *widget) hildon_banner_set_timeout (HILDON_BANNER (banner), 9000); } -#ifndef HILDON_DISABLE_DEPRECATED - -static void -on_animation_clicked (GtkWidget *widget) -{ - GtkWidget *banner = hildon_banner_show_animation (widget, NULL, "Animation banner"); - g_object_ref (banner); - gdk_threads_add_timeout (5000, (GSourceFunc) on_animation_idle, banner); -} - -static void -on_progress_clicked (GtkWidget *widget) -{ - GtkWidget *banner = hildon_banner_show_progress (widget, NULL, "Progress banner"); - g_object_ref (banner); - gdk_threads_add_timeout (5000, (GSourceFunc) on_progress_idle, banner); -} - -#endif - static void on_custom_clicked (GtkWidget *widget) { @@ -145,9 +105,6 @@ main (int argc, { HildonProgram *program; GtkWidget *window, *vbox, *button1; -#ifndef HILDON_DISABLE_DEPRECATED - GtkWidget *button2, *button3; -#endif GtkWidget *button4; hildon_gtk_init (&argc, &argv); @@ -159,22 +116,11 @@ main (int argc, button1 = gtk_button_new_with_label ("Information"); g_signal_connect (button1, "clicked", G_CALLBACK (on_information_clicked), NULL); -#ifndef HILDON_DISABLE_DEPRECATED - button2 = gtk_button_new_with_label ("Animation"); - g_signal_connect (button2, "clicked", G_CALLBACK (on_animation_clicked), NULL); - - button3 = gtk_button_new_with_label ("Progress"); - g_signal_connect (button3, "clicked", G_CALLBACK (on_progress_clicked), NULL); -#endif button4 = gtk_button_new_with_label ("Custom"); g_signal_connect (button4, "clicked", G_CALLBACK (on_custom_clicked), NULL); vbox = gtk_vbox_new (6, FALSE); gtk_box_pack_start (GTK_BOX (vbox), button1, TRUE, TRUE, 0); -#ifndef HILDON_DISABLE_DEPRECATED - gtk_box_pack_start (GTK_BOX (vbox), button2, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (vbox), button3, TRUE, TRUE, 0); -#endif gtk_box_pack_start (GTK_BOX (vbox), button4, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (window), 6); diff --git a/examples/hildon-code-dialog-example.c b/examples/hildon-code-dialog-example.c deleted file mode 100644 index a43ac09..0000000 --- a/examples/hildon-code-dialog-example.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -static gboolean -on_input (void); - -gboolean -on_input (void) -{ - g_debug ("Input in the code dialog!"); - return TRUE; -} - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - GtkDialog *dialog = GTK_DIALOG (hildon_code_dialog_new ()); - g_signal_connect (G_OBJECT (dialog), "input", G_CALLBACK (on_input), NULL); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - return 0; -} - - diff --git a/examples/hildon-color-button-example.c b/examples/hildon-color-button-example.c deleted file mode 100644 index 42a17bb..0000000 --- a/examples/hildon-color-button-example.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); - GtkWidget *button = hildon_color_button_new (); - GtkWidget *label = gtk_label_new ("Pick the color:"); - GtkWidget *hbox = gtk_hbox_new (FALSE, 12); - - gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (dialog->vbox), hbox, TRUE, TRUE, 0); - - gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - GdkColor *color; - g_object_get (G_OBJECT (button), "color", &color, NULL); - - g_debug ("Color is: %d %d %d", color->red, color->green, color->blue); - - return 0; -} - - diff --git a/examples/hildon-color-chooser-example.c b/examples/hildon-color-chooser-example.c deleted file mode 100644 index 46df717..0000000 --- a/examples/hildon-color-chooser-example.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); - GtkWidget *chooser = hildon_color_chooser_new (); - - gtk_box_pack_start (GTK_BOX (dialog->vbox), chooser, TRUE, TRUE, 0); - - gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - return 0; -} - - diff --git a/examples/hildon-get-password-dialog-example.c b/examples/hildon-get-password-dialog-example.c deleted file mode 100644 index d560ceb..0000000 --- a/examples/hildon-get-password-dialog-example.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - GtkDialog *dialog = GTK_DIALOG (hildon_get_password_dialog_new (NULL, TRUE)); - - hildon_get_password_dialog_set_message ((HildonGetPasswordDialog *) dialog, "Enter secret password"); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - g_debug ("Password: %s", hildon_get_password_dialog_get_password ((HildonGetPasswordDialog *) dialog)); - - return 0; -} - - diff --git a/examples/hildon-hvolumebar-example.c b/examples/hildon-hvolumebar-example.c deleted file mode 100644 index c382981..0000000 --- a/examples/hildon-hvolumebar-example.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -void -on_mute_clicked (GtkWidget *clicked, - GObject *bar); - -void -on_mute_clicked (GtkWidget *clicked, - GObject *bar) -{ - gboolean focus; - g_object_get (bar, "mute", &focus, NULL); - g_object_set (bar, "mute", !focus, NULL); -} - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - - GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); - GtkButton *button = GTK_BUTTON (gtk_button_new_with_label ("mute")); - - HildonHVolumebar *bar = HILDON_HVOLUMEBAR (hildon_hvolumebar_new ()); - gtk_widget_set_size_request (GTK_WIDGET (bar), 400, -1); - - gtk_box_pack_start (GTK_BOX (dialog->vbox), GTK_WIDGET (bar), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (dialog->vbox), GTK_WIDGET (button), FALSE, FALSE, 0); - gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE); - - g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (on_mute_clicked), bar); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - return 0; -} - - diff --git a/examples/hildon-hvolumebar-insensitive-example.c b/examples/hildon-hvolumebar-insensitive-example.c deleted file mode 100644 index 1efe41f..0000000 --- a/examples/hildon-hvolumebar-insensitive-example.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); - - HildonHVolumebar *bar_1 = HILDON_HVOLUMEBAR (hildon_hvolumebar_new ()); - HildonHVolumebar *bar_2 = HILDON_HVOLUMEBAR (hildon_hvolumebar_new ()); - gtk_widget_set_size_request (GTK_WIDGET (bar_1), 400, -1); - gtk_widget_set_size_request (GTK_WIDGET (bar_2), 400, -1); - - hildon_volumebar_set_range_insensitive_message (HILDON_VOLUMEBAR (bar_1), "Can't set volume while muted"); - hildon_volumebar_set_range_insensitive_messagef (HILDON_VOLUMEBAR (bar_2), "Can't set volume while %s", "muted"); - - gtk_box_pack_start (GTK_BOX (dialog->vbox), GTK_WIDGET (bar_1), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (dialog->vbox), GTK_WIDGET (bar_2), FALSE, FALSE, 0); - gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - return 0; -} - - diff --git a/examples/hildon-hvolumebar-insensitive-map-example.c b/examples/hildon-hvolumebar-insensitive-map-example.c deleted file mode 100644 index 567520c..0000000 --- a/examples/hildon-hvolumebar-insensitive-map-example.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); - - HildonHVolumebar *bar = HILDON_HVOLUMEBAR (hildon_hvolumebar_new ()); - gtk_widget_set_size_request (GTK_WIDGET (bar), 400, -1); - - gtk_widget_set_sensitive (GTK_WIDGET (bar), FALSE); - gtk_box_pack_start (GTK_BOX (dialog->vbox), GTK_WIDGET (bar), FALSE, FALSE, 0); - gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - return 0; -} - - diff --git a/examples/hildon-hvolumebar-timer-example.c b/examples/hildon-hvolumebar-timer-example.c deleted file mode 100644 index 77263a8..0000000 --- a/examples/hildon-hvolumebar-timer-example.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -gboolean -on_idle (void); - -GtkDialog* dialog = NULL; - -HildonHVolumebar* bar = NULL; - -int cycle = 0; - -gboolean -on_idle (void) -{ - - if (dialog == NULL) { - - g_debug ("Creating the dialog!"); - - dialog = GTK_DIALOG (gtk_dialog_new ()); - - bar = HILDON_HVOLUMEBAR (hildon_hvolumebar_new ()); - gtk_widget_set_size_request (GTK_WIDGET (bar), 400, -1); - hildon_helper_set_insensitive_message ((GtkWidget *) bar, "Insensitive"); - hildon_volumebar_set_range_insensitive_message (HILDON_VOLUMEBAR (bar), "Insensitive range"); - - gtk_box_pack_start (GTK_BOX (dialog->vbox), GTK_WIDGET (bar), FALSE, FALSE, 0); - gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - gtk_widget_hide (GTK_WIDGET (dialog)); - - } else { - - if (cycle == 0) { - g_debug ("Making insensitive..."); - gtk_widget_set_sensitive (GTK_WIDGET (bar), FALSE); - } else if (cycle == 1) { - g_debug ("Making sensitive..."); - gtk_widget_set_sensitive (GTK_WIDGET (bar), TRUE); - } else if (cycle == 2) { - g_debug ("Showing back..."); - gtk_widget_show (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - gtk_widget_hide (GTK_WIDGET (dialog)); - } - - cycle = (cycle + 1) % 3; - } - - gdk_threads_add_timeout (2000, (GSourceFunc) on_idle, NULL); - return FALSE; -} - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - gdk_threads_add_timeout (2000, (GSourceFunc) on_idle, NULL); - - gtk_main (); - - return 0; -} - - diff --git a/examples/hildon-icon-sizes-example.c b/examples/hildon-icon-sizes-example.c index ae54bc9..8d99a49 100644 --- a/examples/hildon-icon-sizes-example.c +++ b/examples/hildon-icon-sizes-example.c @@ -41,11 +41,7 @@ main (int argc, g_debug ("Thumb pixel size: %d", HILDON_ICON_PIXEL_SIZE_THUMB); g_debug ("Large pixel size: %d", HILDON_ICON_PIXEL_SIZE_LARGE); g_debug ("Extra large pixel size: %d", HILDON_ICON_PIXEL_SIZE_XLARGE); -#ifndef HILDON_DISABLE_DEPRECATED - g_debug ("Toolbar pixel size: %d", HILDON_ICON_PIXEL_SIZE_TOOLBAR); -#else g_debug ("Toolbar pixel size: %d", HILDON_ICON_PIXEL_SIZE_FINGER); -#endif return 0; } diff --git a/examples/hildon-login-dialog-example.c b/examples/hildon-login-dialog-example.c deleted file mode 100644 index c603ee1..0000000 --- a/examples/hildon-login-dialog-example.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - GtkDialog *dialog = GTK_DIALOG (hildon_login_dialog_new (NULL)); - - hildon_login_dialog_set_message ((HildonLoginDialog *) dialog, "Enter password to login"); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - g_debug ("Password: %s", hildon_login_dialog_get_password ((HildonLoginDialog *) dialog)); - g_debug ("Username: %s", hildon_login_dialog_get_username ((HildonLoginDialog *) dialog)); - - return 0; -} - - diff --git a/examples/hildon-set-password-dialog-example.c b/examples/hildon-set-password-dialog-example.c deleted file mode 100644 index f025a9b..0000000 --- a/examples/hildon-set-password-dialog-example.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - GtkDialog *dialog = GTK_DIALOG (hildon_set_password_dialog_new (NULL, TRUE)); - - hildon_set_password_dialog_set_message ((HildonSetPasswordDialog *) dialog, "Enter new password"); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - g_debug ("Password: %s", hildon_set_password_dialog_get_password ((HildonSetPasswordDialog *) dialog)); - - return 0; -} - - diff --git a/examples/hildon-vvolumebar-example.c b/examples/hildon-vvolumebar-example.c deleted file mode 100644 index 19dadea..0000000 --- a/examples/hildon-vvolumebar-example.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is a part of hildon examples - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <hildon/hildon.h> - -int -main (int argc, - char **argv) -{ - hildon_gtk_init (&argc, &argv); - - GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new ()); - - HildonVVolumebar *bar = HILDON_VVOLUMEBAR (hildon_vvolumebar_new ()); - gtk_widget_set_size_request (GTK_WIDGET (bar), -1, 300); - - gtk_box_pack_start (GTK_BOX (dialog->vbox), GTK_WIDGET (bar), FALSE, FALSE, 0); - gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE); - - gtk_widget_show_all (GTK_WIDGET (dialog)); - gtk_dialog_run (dialog); - - return 0; -} - - diff --git a/hildon/Makefile.am b/hildon/Makefile.am index 40ae7bb..3f578da 100644 --- a/hildon/Makefile.am +++ b/hildon/Makefile.am @@ -27,18 +27,8 @@ libhildon_@API_VERSION_MAJOR@_la_CFLAGS = \ libhildon_@API_VERSION_MAJOR@_la_SOURCES = \ hildon-private.c \ - hildon-controlbar.c \ - hildon-seekbar.c \ hildon-note.c \ - hildon-volumebar.c \ hildon-sound.c \ - hildon-volumebar-range.c \ - hildon-hvolumebar.c \ - hildon-vvolumebar.c \ - hildon-calendar-popup.c \ - hildon-date-editor.c \ - hildon-time-editor.c \ - hildon-time-picker.c \ hildon-date-selector.c \ hildon-time-selector.c \ hildon-touch-selector.c \ @@ -48,18 +38,7 @@ libhildon_@API_VERSION_MAJOR@_la_SOURCES = \ hildon-date-button.c \ hildon-time-button.c \ hildon-helper.c \ - hildon-weekday-picker.c \ - hildon-number-editor.c \ - hildon-range-editor.c \ - hildon-get-password-dialog.c \ - hildon-set-password-dialog.c \ - hildon-sort-dialog.c \ - hildon-font-selection-dialog.c \ - hildon-login-dialog.c \ hildon-wizard-dialog.c \ - hildon-color-chooser.c \ - hildon-color-button.c \ - hildon-color-chooser-dialog.c \ hildon-defines.c \ hildon-find-toolbar.c \ hildon-edit-toolbar.c \ @@ -71,21 +50,15 @@ libhildon_@API_VERSION_MAJOR@_la_SOURCES = \ hildon-animation-actor.c \ hildon-remote-texture.c \ hildon-program.c \ - hildon-code-dialog.c \ hildon-enum-types.c \ hildon-marshalers.c \ - hildon-calendar.c \ hildon-pannable-area.c \ hildon-entry.c \ hildon-text-view.c \ - hildon-bread-crumb-trail.c \ - hildon-bread-crumb.c \ - hildon-bread-crumb-widget.c \ hildon-app-menu.c \ hildon-button.c \ hildon-check-button.c \ hildon-gtk.c \ - hildon-dialog.c \ hildon-main.c \ hildon-live-search.c @@ -97,33 +70,14 @@ libhildon_@API_VERSION_MAJOR@_includedir = \ $(includedir)/$(PACKAGE)-$(API_VERSION_MAJOR)/$(PACKAGE) libhildon_@API_VERSION_MAJOR@_public_headers = \ - hildon-banner.h \ - hildon-calendar-popup.h \ hildon-caption.h \ - hildon-code-dialog.h \ - hildon-color-button.h \ - hildon-color-chooser-dialog.h \ - hildon-color-chooser.h \ - hildon-controlbar.h \ - hildon-date-editor.h \ hildon-defines.h \ hildon-find-toolbar.h \ hildon-edit-toolbar.h \ hildon-helper.h \ - hildon-font-selection-dialog.h \ - hildon-get-password-dialog.h \ - hildon-hvolumebar.h \ - hildon-login-dialog.h \ hildon-note.h \ - hildon-number-editor.h \ hildon-program.h \ - hildon-range-editor.h \ - hildon-seekbar.h \ - hildon-set-password-dialog.h \ - hildon-sort-dialog.h \ hildon-sound.h \ - hildon-time-editor.h \ - hildon-time-picker.h \ hildon-date-selector.h \ hildon-time-selector.h \ hildon-touch-selector.h \ @@ -133,10 +87,6 @@ libhildon_@API_VERSION_MAJOR@_public_headers = \ hildon-picker-button.h \ hildon-date-button.h \ hildon-time-button.h \ - hildon-volumebar-range.h \ - hildon-volumebar.h \ - hildon-vvolumebar.h \ - hildon-weekday-picker.h \ hildon.h \ hildon-window.h \ hildon-stackable-window.h \ @@ -144,14 +94,10 @@ libhildon_@API_VERSION_MAJOR@_public_headers = \ hildon-animation-actor.h \ hildon-remote-texture.h \ hildon-wizard-dialog.h \ - hildon-calendar.h \ hildon-pannable-area.h \ hildon-entry.h \ hildon-text-view.h \ - hildon-bread-crumb-trail.h \ - hildon-bread-crumb.h \ hildon-app-menu.h \ - hildon-dialog.h \ hildon-button.h \ hildon-check-button.h \ hildon-gtk.h \ @@ -164,41 +110,20 @@ libhildon_@API_VERSION_MAJOR@_include_HEADERS = \ $(libhildon_@API_VERSION_MAJOR@_public_headers) \ $(libhildon_@API_VERSION_MAJOR@_built_public_headers) -noinst_HEADERS = hildon-calendar-popup-private.h \ - hildon-private.h \ +noinst_HEADERS = hildon-private.h \ hildon-caption-private.h \ - hildon-code-dialog-private.h \ hildon-picker-button-private.h \ - hildon-color-button-private.h \ - hildon-color-chooser-dialog-private.h \ - hildon-color-chooser-private.h \ - hildon-controlbar-private.h \ - hildon-date-editor-private.h \ hildon-edit-toolbar-private.h \ hildon-find-toolbar-private.h \ - hildon-font-selection-dialog-private.h \ - hildon-get-password-dialog-private.h \ - hildon-login-dialog-private.h \ hildon-note-private.h \ - hildon-number-editor-private.h \ hildon-program-private.h \ - hildon-range-editor-private.h \ - hildon-seekbar-private.h \ - hildon-set-password-dialog-private.h \ - hildon-sort-dialog-private.h \ - hildon-time-editor-private.h \ - hildon-time-picker-private.h \ - hildon-volumebar-private.h \ - hildon-weekday-picker-private.h \ hildon-window-private.h \ hildon-stackable-window-private.h \ hildon-window-stack-private.h \ hildon-animation-actor-private.h \ hildon-remote-texture-private.h \ hildon-wizard-dialog-private.h \ - hildon-calendar-private.h \ hildon-app-menu-private.h \ - hildon-bread-crumb-widget.h \ hildon-touch-selector-private.h # Don't build the library until we have built the header that it needs: @@ -220,7 +145,6 @@ hildon-enum-types.h: @REBUILD@ $(libhildon_$(API_VERSION_MAJOR)_public_headers) hildon-enum-types.c: @REBUILD@ $(libhildon_$(API_VERSION_MAJOR)_public_headers) Makefile $(AM_V_GEN) (cd $(srcdir) && glib-mkenums \ - --fhead "#undef HILDON_DISABLE_DEPRECATED\n" \ --fhead "#include \"hildon.h\"\n" \ --fhead "#include <glib-object.h>" \ --fprod "\n/* enumerations from \"@filename@\" */" \ diff --git a/hildon/hildon-banner.c b/hildon/hildon-banner.c index cd5dab5..7e0c48e 100644 --- a/hildon/hildon-banner.c +++ b/hildon/hildon-banner.c @@ -81,8 +81,6 @@ #include <X11/Xatom.h> #include <gdk/gdkx.h> -#undef HILDON_DISABLE_DEPRECATED - #include "hildon-banner.h" #include "hildon-private.h" #include "hildon-defines.h" @@ -180,16 +178,8 @@ hildon_banner_realize (GtkWidget *widget); static void hildon_banner_class_init (HildonBannerClass *klass); -static void -hildon_banner_init (HildonBanner *self); - static void -hildon_banner_ensure_child (HildonBanner *self, - GtkWidget *user_widget, - guint pos, - GType type, - const gchar *first_property, - ...); +hildon_banner_init (HildonBanner *self); static HildonBanner* hildon_banner_get_instance_for_widget (GtkWidget *widget, @@ -840,49 +830,6 @@ hildon_banner_init (HildonBanner *self) gtk_widget_add_events (GTK_WIDGET (self), GDK_BUTTON_PRESS_MASK); } -/* Makes sure that icon/progress item contains the desired type - of item. If possible, tries to avoid creating a new widget but - reuses the existing one */ -static void -hildon_banner_ensure_child (HildonBanner *self, - GtkWidget *user_widget, - guint pos, - GType type, - const gchar *first_property, - ...) -{ - GtkWidget *widget; - va_list args; - HildonBannerPrivate *priv = HILDON_BANNER_GET_PRIVATE (self); - - g_assert (priv); - - widget = priv->main_item; - va_start (args, first_property); - - /* Reuse existing widget if possible */ - if (! user_widget && G_TYPE_CHECK_INSTANCE_TYPE (widget, type)) - { - g_object_set_valist (G_OBJECT (widget), first_property, args); - } - else - { - /* We have to abandon old content widget */ - if (widget) - gtk_container_remove (GTK_CONTAINER (priv->layout), widget); - - /* Use user provided widget or create a new one */ - priv->main_item = widget = user_widget ? - user_widget : GTK_WIDGET (g_object_new_valist(type, first_property, args)); - gtk_box_pack_start (GTK_BOX (priv->layout), widget, FALSE, FALSE, 0); - } - - /* We make sure that the widget exists in desired position. Different - banners place this child widget to different places */ - gtk_box_reorder_child (GTK_BOX (priv->layout), widget, pos); - va_end (args); -} - /* Creates a new banner instance or uses an existing one */ static HildonBanner* hildon_banner_get_instance_for_widget (GtkWidget *widget, @@ -1084,117 +1031,6 @@ hildon_banner_show_information_with_markup (GtkWidget *widget, return (GtkWidget *) banner; } -/** - * hildon_banner_show_animation: - * @widget: the #GtkWidget that wants to display banner - * @animation_name: since Hildon 2.2 this parameter is not used - * anymore and any value that you pass will be - * ignored - * @text: the text to display. - * - * Shows an animated progress notification. It's recommended not to try - * to show more than one progress notification at a time, since - * they will appear on top of each other. You can use progress - * notifications with timed banners. In this case the banners are - * located so that you can somehow see both. - * - * Unlike information banners (created with - * hildon_banner_show_information()), animation banners are not - * destroyed automatically using a timeout. You have to destroy them - * yourself. - * - * Please note also that these banners are destroyed automatically if the - * window they are attached to is closed. The pointer that you receive - * with this function does not contain additional references, so it - * can become invalid without warning (this is true for all toplevel - * windows in gtk). To make sure that the banner does not disappear - * automatically, you can separately ref the return value (this - * doesn't prevent the banner from disappearing, just the object from - * being finalized). In this case you have to call - * gtk_widget_destroy() followed by g_object_unref(). - * - * Returns: a #HildonBanner widget. You must call gtk_widget_destroy() - * once you are done with the banner. - * - * Deprecated: Hildon 2.2: use - * hildon_gtk_window_set_progress_indicator() instead. - */ -GtkWidget* -hildon_banner_show_animation (GtkWidget *widget, - const gchar *animation_name, - const gchar *text) -{ - HildonBanner *banner; - GtkWidget *image_widget; - HildonBannerPrivate *priv; - - g_return_val_if_fail (text != NULL, NULL); - - image_widget = hildon_private_create_animation ( - HILDON_BANNER_ANIMATION_FRAMERATE, - HILDON_BANNER_ANIMATION_TMPL, - HILDON_BANNER_ANIMATION_NFRAMES); - - /* Prepare banner */ - banner = hildon_banner_get_instance_for_widget (widget, FALSE); - hildon_banner_ensure_child (banner, image_widget, 0, - GTK_TYPE_IMAGE, "yalign", 0.0, NULL); - - priv = HILDON_BANNER_GET_PRIVATE (banner); - priv->name_suffix = "animation"; - banner_do_set_text (banner, text, FALSE); - hildon_banner_bind_style (banner); - - /* And show it */ - reshow_banner (banner); - - return (GtkWidget *) banner; -} - -/** - * hildon_banner_show_progress: - * @widget: the #GtkWidget that wants to display banner - * @bar: since Hildon 2.2 this parameter is not used anymore and - * any value that you pass will be ignored - * @text: text to display. - * - * Shows progress notification. See hildon_banner_show_animation() - * for more information. - * - * Returns: a #HildonBanner widget. You must call #gtk_widget_destroy - * once you are done with the banner. - * - * Deprecated: Hildon 2.2: use hildon_gtk_window_set_progress_indicator() instead. - */ -GtkWidget* -hildon_banner_show_progress (GtkWidget *widget, - GtkProgressBar *bar, - const gchar *text) -{ - HildonBanner *banner; - HildonBannerPrivate *priv; - - g_return_val_if_fail (text != NULL, NULL); - - /* Prepare banner */ - banner = hildon_banner_get_instance_for_widget (widget, FALSE); - priv = HILDON_BANNER_GET_PRIVATE (banner); - g_assert (priv); - - priv->name_suffix = "progress"; - unpack_main_widget_pack_label (banner); - banner_do_set_text (banner, text, FALSE); - hildon_banner_bind_style (banner); - - if (priv->parent) - hildon_gtk_window_set_progress_indicator (priv->parent, 1); - - /* Show the banner */ - reshow_banner (banner); - - return GTK_WIDGET (banner); -} - /** * hildon_banner_show_custom_widget: @@ -1293,27 +1129,6 @@ hildon_banner_set_markup (HildonBanner *self, } /** - * hildon_banner_set_fraction: - * @self: a #HildonBanner widget - * @fraction: #gdouble - * - * The fraction is the completion of progressbar, - * the scale is from 0.0 to 1.0. - * Sets the amount of fraction the progressbar has. - * - * Note that this method only has effect if @self was created with - * hildon_banner_show_progress() - * - * Deprecated: This function does nothing. As of Hildon 2.2, hildon - * banners don't have progress bars. - */ -void -hildon_banner_set_fraction (HildonBanner *self, - gdouble fraction) -{ -} - -/** * hildon_banner_set_timeout: * @self: a #HildonBanner widget * @timeout: timeout to set in miliseconds. @@ -1340,34 +1155,3 @@ hildon_banner_set_timeout (HildonBanner *self, priv->timeout = timeout; } -/** - * hildon_banner_set_icon: - * @self: a #HildonBanner widget - * @icon_name: the name of icon to use. Can be %NULL for default icon - * - * Sets the icon to be used in the banner. - * - * Deprecated: This function does nothing. As of hildon 2.2, hildon - * banners don't allow changing their icons. - */ -void -hildon_banner_set_icon (HildonBanner *self, - const gchar *icon_name) -{ -} - -/** - * hildon_banner_set_icon_from_file: - * @self: a #HildonBanner widget - * @icon_file: the filename of icon to use. Can be %NULL for default icon - * - * Sets the icon from its filename to be used in the banner. - * - * Deprecated: This function does nothing. As of hildon 2.2, hildon - * banners don't allow changing their icons. - */ -void -hildon_banner_set_icon_from_file (HildonBanner *self, - const gchar *icon_file) -{ -} diff --git a/hildon/hildon-banner.h b/hildon/hildon-banner.h index d461efa..e07bde4 100644 --- a/hildon/hildon-banner.h +++ b/hildon/hildon-banner.h @@ -77,18 +77,6 @@ hildon_banner_show_information_with_markup (GtkWidget *widget, const gchar *icon_name, const gchar *markup); -#ifndef HILDON_DISABLE_DEPRECATED -GtkWidget* -hildon_banner_show_animation (GtkWidget *widget, - const gchar *animation_name, - const gchar *text); - -GtkWidget* -hildon_banner_show_progress (GtkWidget *widget, - GtkProgressBar *bar, - const gchar *text); -#endif /* HILDON_DISABLE_DEPRECATED */ - void hildon_banner_set_text (HildonBanner *self, const gchar *text); @@ -97,20 +85,6 @@ void hildon_banner_set_markup (HildonBanner *self, const gchar *markup); -#ifndef HILDON_DISABLE_DEPRECATED -void -hildon_banner_set_fraction (HildonBanner *self, - gdouble fraction); - -void -hildon_banner_set_icon (HildonBanner *self, - const gchar *icon_name); - -void -hildon_banner_set_icon_from_file (HildonBanner *self, - const gchar *icon_file); -#endif /* HILDON_DISABLE_DEPRECATED */ - void hildon_banner_set_timeout (HildonBanner *self, guint timeout); diff --git a/hildon/hildon-bread-crumb-trail.c b/hildon/hildon-bread-crumb-trail.c deleted file mode 100644 index 6639136..0000000 --- a/hildon/hildon-bread-crumb-trail.c +++ /dev/null @@ -1,795 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2007 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * Author: Xan Lopez <xan.lopez@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - - -/** - * SECTION:hildon-bread-crumb-trail - * @short_description: Widget used to represent a specific path in a hierarchical tree. - * Stability: Unstable - * - * HildonBreadCrumbTrail is a GTK widget used to represent the currently active path in - * some kind of hierarchical structure (file system, media library, structured document, etc). - * - * It has built-in support for text and icon bread crumbs, but the trail only requires a very - * simple interface to be implemented for its children and thus new types of items can be - * implemented if needed. See #HildonBreadCrumb for more details. - * - * #HildonBreadCrumbTrail is deprecated since hildon 2.2. You should instead use - * #HildonStackableWindow to represent hierarchical structure in - * applications. - */ - -#undef HILDON_DISABLE_DEPRECATED - -#include <gdk/gdkkeysyms.h> - -#include "hildon-marshalers.h" -#include "hildon-bread-crumb-trail.h" -#include "hildon-bread-crumb-widget.h" - -#define HILDON_BREAD_CRUMB_TRAIL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_BREAD_CRUMB_TRAIL, HildonBreadCrumbTrailPrivate)) - -struct _HildonBreadCrumbTrailPrivate -{ - GtkWidget *back_button; - GList *item_list; - GtkWidget *arrow; -}; - -/* Signals */ - -enum { - CRUMB_CLICKED, - MOVE_PARENT, - LAST_SIGNAL -}; - -/* Properties */ - -enum { - PROP_0 -}; - -static void hildon_bread_crumb_trail_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void hildon_bread_crumb_trail_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void hildon_bread_crumb_trail_add (GtkContainer *container, - GtkWidget *widget); -static void hildon_bread_crumb_trail_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); -static void hildon_bread_crumb_trail_remove (GtkContainer *container, - GtkWidget *widget); -static void hildon_bread_crumb_trail_finalize (GObject *object); -static void hildon_bread_crumb_trail_scroll_back (GtkWidget *button, - HildonBreadCrumbTrail *bct); -static void hildon_bread_crumb_trail_update_back_button_sensitivity (HildonBreadCrumbTrail *bct); -static void hildon_bread_crumb_trail_move_parent (HildonBreadCrumbTrail *bct); - -static gpointer get_bread_crumb_id (HildonBreadCrumb *item); - -static guint bread_crumb_trail_signals[LAST_SIGNAL] = { 0 }; - -/* GType methods */ - -G_DEFINE_TYPE (HildonBreadCrumbTrail, hildon_bread_crumb_trail, GTK_TYPE_CONTAINER) - -static void -hildon_bread_crumb_trail_class_init (HildonBreadCrumbTrailClass *klass) -{ - GObjectClass *gobject_class = (GObjectClass*)klass; - GtkObjectClass *object_class = (GtkObjectClass*)klass; - GtkWidgetClass *widget_class = (GtkWidgetClass*)klass; - GtkContainerClass *container_class = (GtkContainerClass*)klass; - GtkBindingSet *binding_set; - - /* GObject signals */ - gobject_class->finalize = hildon_bread_crumb_trail_finalize; - - /* GtkWidget signals */ - widget_class->size_request = hildon_bread_crumb_trail_size_request; - widget_class->size_allocate = hildon_bread_crumb_trail_size_allocate; - - /* GtkContainer signals */ - container_class->add = hildon_bread_crumb_trail_add; - container_class->forall = hildon_bread_crumb_trail_forall; - container_class->remove = hildon_bread_crumb_trail_remove; - - /* HildonBreadCrumbTrail signals */ - klass->move_parent = hildon_bread_crumb_trail_move_parent; - - /* Style properties */ - -#define _BREAD_CRUMB_TRAIL_MINIMUM_WIDTH 10 - - /* FIXME: is this the best way to do it? */ - gtk_widget_class_install_style_property (widget_class, - g_param_spec_int ("minimum-width", - "Minimum width", - "The minimum width in characters the children widgets will request", - 0, - G_MAXINT, - _BREAD_CRUMB_TRAIL_MINIMUM_WIDTH, - G_PARAM_READABLE)); - -#define _BREAD_CRUMB_TRAIL_ARROW_SIZE 34 - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_int ("arrow-size", - "Arrow size", - "Size of the back button arrow", - 0, - G_MAXINT, - _BREAD_CRUMB_TRAIL_ARROW_SIZE, - G_PARAM_READABLE)); - /* Signals */ - bread_crumb_trail_signals[CRUMB_CLICKED] = - g_signal_new ("crumb-clicked", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HildonBreadCrumbTrailClass, crumb_clicked), - g_signal_accumulator_true_handled, NULL, - _hildon_marshal_BOOLEAN__POINTER, - G_TYPE_BOOLEAN, 1, - G_TYPE_POINTER); - - bread_crumb_trail_signals[MOVE_PARENT] = - g_signal_new ("move-parent", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (HildonBreadCrumbTrailClass, move_parent), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - - /* Binding set */ - binding_set = gtk_binding_set_by_class (widget_class); - - gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, - "move-parent", 0); - gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0, - "move-parent", 0); - - /* Private data */ - g_type_class_add_private (gobject_class, sizeof (HildonBreadCrumbTrailPrivate)); -} - -static void -hildon_bread_crumb_trail_finalize (GObject *object) -{ - HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL (object)->priv; - - g_list_free (priv->item_list); - - G_OBJECT_CLASS (hildon_bread_crumb_trail_parent_class)->finalize (object); -} - -static void -hildon_bread_crumb_trail_move_parent (HildonBreadCrumbTrail *bct) -{ - if (g_list_length (bct->priv->item_list) > 1) - { - g_signal_emit_by_name (HILDON_BREAD_CRUMB (bct->priv->item_list->next->data), - "crumb-activated"); - } -} - -static void -hildon_bread_crumb_trail_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - GList *p; - GtkRequisition child_requisition; - HildonBreadCrumbTrail *bct; - HildonBreadCrumbTrailPrivate *priv; - gint minimum_width, width = 0; - PangoLayout *layout; - gchar *tmp = NULL; - - bct= HILDON_BREAD_CRUMB_TRAIL (widget); - priv = bct->priv; - - requisition->height = 0; - requisition->width = 0; - - gtk_widget_size_request (priv->back_button, &child_requisition); - requisition->width = child_requisition.width; - requisition->height = child_requisition.height; - - if (priv->item_list) - { - /* Add minimum width for one item */ - /* TODO: this can be probably cached */ - gtk_widget_style_get (widget, - "minimum-width", &minimum_width, - NULL); - - tmp = g_strnfill ((gsize)minimum_width, 'm'); - layout = gtk_widget_create_pango_layout (widget, tmp); - g_free (tmp); - pango_layout_get_size (layout, &width, NULL); - requisition->width += PANGO_PIXELS (width); - g_object_unref (layout); - } - - /* Button requisitions */ - for (p = priv->item_list; p; p = p->next) - { - GtkWidget *child = GTK_WIDGET (p->data); - - if (GTK_WIDGET_VISIBLE (child)) - gtk_widget_size_request (child, &child_requisition); - } - - /* Border width */ - requisition->width += GTK_CONTAINER (widget)->border_width * 2; - requisition->height += GTK_CONTAINER (widget)->border_width * 2; - - widget->requisition = *requisition; -} - -/* Document me please */ - -static void -hildon_bread_crumb_trail_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GtkRequisition req; - gint natural_width, natural_height; - HildonBreadCrumb *item; - GtkAllocation child_allocation; - GtkRequisition child_requisition; - GtkWidget *child; - gint allocation_width; - gint border_width, width; - gint extra_space; - GList *p, *first_show, *first_hide; - gint back_button_size; - HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL (widget)->priv; - gboolean rtl; - - /* Get the rtl status */ - rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL); - - widget->allocation = *allocation; - - border_width = (gint) GTK_CONTAINER (widget)->border_width; - allocation_width = allocation->width - 2 * border_width; - - /* Allocate the back button */ - if (rtl) - child_allocation.x = allocation->width - border_width; - else - child_allocation.x = allocation->x + border_width; - - child_allocation.y = allocation->y + border_width; - gtk_widget_get_child_requisition (priv->back_button, &child_requisition); - /* We want the back button to be a square */ - back_button_size = MAX (child_requisition.width, child_requisition.height); - child_allocation.width = child_allocation.height = back_button_size; - - if (rtl) - child_allocation.x -= back_button_size; - - gtk_widget_size_allocate (priv->back_button, &child_allocation); - - if (!rtl) - child_allocation.x += back_button_size; - - /* If there are no buttons there's nothing else to do */ - if (priv->item_list == NULL) - return; - - /* We find out how many buttons can we show, starting from the - the last one in the logical path (the first item in the list) */ - - width = back_button_size; - p = priv->item_list; - first_show = NULL; - first_hide = NULL; - extra_space = 0; - - for (p = priv->item_list; p; p = p->next) - { - item = HILDON_BREAD_CRUMB (p->data); - child = GTK_WIDGET (item); - - /* Does the widget fit with its natural size? */ - hildon_bread_crumb_get_natural_size (item, - &natural_width, - &natural_height); - - if (width + natural_width <= allocation_width) - { - /* Yes, it does */ - first_show = p; - first_hide = p->next; - width += natural_width; - } - else - { - /* No, it doesn't. Allocate as much as possible - and stop */ - child_allocation.width = allocation_width - width; - - gtk_widget_size_request (child, &req); - - if (child_allocation.width > req.width) - { - first_hide = p->next; - gtk_widget_set_child_visible (child, TRUE); - - if (rtl) - child_allocation.x -= child_allocation.width; - - gtk_widget_size_allocate (child, &child_allocation); - - if (!rtl) - child_allocation.x += child_allocation.width; - } - else - { - extra_space = child_allocation.width; - } - - break; - } - } - - /* Not enough items to fill the breadcrumb? */ - if (p == NULL && width < allocation_width) - { - extra_space = allocation_width - width; - } - - /* Allocate the other buttons */ - for (p = first_show; p; p = p->prev) - { - item = HILDON_BREAD_CRUMB (p->data); - child = GTK_WIDGET (item); - - /* Does the widget fit with its natural size? */ - hildon_bread_crumb_get_natural_size (item, - &natural_width, - &natural_height); - - /* If I'm the last and there's extra space, use it */ - if (p->prev == NULL && extra_space != 0) - { - natural_width += extra_space; - } - - child_allocation.width = natural_width; - gtk_widget_set_child_visible (child, TRUE); - - if (rtl) - child_allocation.x -= child_allocation.width; - - gtk_widget_size_allocate (child, &child_allocation); - - if (!rtl) - child_allocation.x += child_allocation.width; - } - - for (p = first_hide; p; p = p->next) - { - item = HILDON_BREAD_CRUMB (p->data); - gtk_widget_set_child_visible (GTK_WIDGET (item), FALSE); - } -} - -static gpointer -get_bread_crumb_id (HildonBreadCrumb *item) -{ - return g_object_get_data (G_OBJECT (item), "bread-crumb-id"); -} - -static void -crumb_activated_cb (GtkWidget *button, - HildonBreadCrumbTrail *bct) -{ - gboolean signal_handled = FALSE; - - g_signal_emit (bct, bread_crumb_trail_signals[CRUMB_CLICKED], 0, - get_bread_crumb_id (HILDON_BREAD_CRUMB (button)), - &signal_handled); - - if (signal_handled == FALSE) - { - GtkWidget *child; - gboolean focus_last_item = FALSE; - HildonBreadCrumbTrailPrivate *priv; - - priv = bct->priv; - - child = GTK_WIDGET (priv->item_list->data); - - /* We remove the tip of the list until we hit the clicked button */ - while (child && child != button) - { - if (GTK_WIDGET_HAS_FOCUS (child)) - focus_last_item = TRUE; - - gtk_container_remove (GTK_CONTAINER (bct), child); - - if (priv->item_list == NULL) - return; - - child = GTK_WIDGET (priv->item_list->data); - } - - if (focus_last_item) - gtk_widget_grab_focus (GTK_WIDGET (bct->priv->item_list->data)); - } -} - -static void -hildon_bread_crumb_trail_add (GtkContainer *container, - GtkWidget *widget) -{ - gtk_widget_set_parent (widget, GTK_WIDGET (container)); - - if (HILDON_IS_BREAD_CRUMB (widget)) - { - HildonBreadCrumbTrail *bct = HILDON_BREAD_CRUMB_TRAIL (container); - - g_signal_connect (G_OBJECT (widget), "crumb-activated", - G_CALLBACK (crumb_activated_cb), container); - - bct->priv->item_list = g_list_prepend (bct->priv->item_list, widget); - - hildon_bread_crumb_trail_update_back_button_sensitivity (bct); - } -} - -static void -hildon_bread_crumb_trail_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - g_return_if_fail (callback != NULL); - g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (container)); - - GList *children; - HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL (container)->priv; - - children = priv->item_list; - - while (children) - { - GtkWidget *child; - child = GTK_WIDGET (children->data); - children = children->next; - - (*callback) (child, callback_data); - } - - if (include_internals && priv->back_button) - { - (*callback) (priv->back_button, callback_data); - } -} - -static void -hildon_bread_crumb_trail_remove (GtkContainer *container, - GtkWidget *widget) -{ - GList *p, *next; - HildonBreadCrumbTrailPrivate *priv; - gboolean was_visible = GTK_WIDGET_VISIBLE (widget); - - priv = HILDON_BREAD_CRUMB_TRAIL (container)->priv; - - p = priv->item_list; - - while (p) - { - next = p->next; - - if (widget == GTK_WIDGET (p->data)) - { - g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (crumb_activated_cb), - HILDON_BREAD_CRUMB_TRAIL (container)); - gtk_widget_unparent (widget); - - priv->item_list = g_list_delete_link (priv->item_list, p); - - hildon_bread_crumb_trail_update_back_button_sensitivity (HILDON_BREAD_CRUMB_TRAIL (container)); - - if (was_visible) - { - gtk_widget_queue_resize (GTK_WIDGET (container)); - } - } - - p = next; - } -} - -static void -hildon_bread_crumb_trail_update_back_button_sensitivity (HildonBreadCrumbTrail *bct) -{ - guint list_length; - HildonBreadCrumbTrailPrivate *priv = bct->priv; - - list_length = g_list_length (priv->item_list); - - if (list_length <= 1) - { - gtk_widget_set_sensitive (priv->back_button, FALSE); - } - else - { - gtk_widget_set_sensitive (priv->back_button, TRUE); - } -} - -static GtkWidget* -create_back_button (HildonBreadCrumbTrail *bct) -{ - GtkWidget *button; - GtkWidget *arrow; - gint arrow_size; - - gtk_widget_push_composite_child (); - - button = gtk_button_new (); - gtk_widget_set_name (button, "hildon-bread-crumb-back-button"); - gtk_widget_set_sensitive (button, FALSE); - - arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE); - bct->priv->arrow = arrow; - gtk_widget_style_get (GTK_WIDGET (bct), - "arrow-size", &arrow_size, - NULL); - gtk_widget_set_size_request (arrow, arrow_size, arrow_size); - - gtk_container_add (GTK_CONTAINER (button), arrow); - gtk_container_add (GTK_CONTAINER (bct), button); - gtk_widget_show_all (button); - - gtk_widget_pop_composite_child (); - - return button; -} - -static void -hildon_bread_crumb_trail_init (HildonBreadCrumbTrail *bct) -{ - HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL_GET_PRIVATE (bct); - - GTK_WIDGET_SET_FLAGS (bct, GTK_NO_WINDOW); - gtk_widget_set_redraw_on_allocate (GTK_WIDGET (bct), FALSE); - - bct->priv = priv; - priv->item_list = NULL; - - priv->back_button = create_back_button (bct); - g_signal_connect (priv->back_button, "clicked", - G_CALLBACK (hildon_bread_crumb_trail_scroll_back), - bct); -} - -static void -hildon_bread_crumb_trail_scroll_back (GtkWidget *button, - HildonBreadCrumbTrail *bct) -{ - hildon_bread_crumb_trail_move_parent (bct); -} - -static void -attach_bread_crumb (HildonBreadCrumbTrail *bct, - GtkWidget *bread_crumb, - gpointer id, - GDestroyNotify destroy) -{ - g_object_set_data_full (G_OBJECT (bread_crumb), "bread-crumb-id", id, destroy); - - gtk_container_add (GTK_CONTAINER (bct), bread_crumb); - - gtk_widget_show (bread_crumb); -} - -/* PUBLIC API */ - -/** - * hildon_bread_crumb_trail_new: - * - * Creates a new #HildonBreadCrumbTrail widget. - * - * Returns: a #GtkWidget pointer of newly created bread crumb trail - * widget - * - * Stability: Unstable - */ - -GtkWidget* -hildon_bread_crumb_trail_new (void) -{ - return GTK_WIDGET (g_object_new (HILDON_TYPE_BREAD_CRUMB_TRAIL, NULL)); -} - -/** - * hildon_bread_crumb_trail_push: - * @bct: pointer to #HildonBreadCrumbTrail - * @item: the #HildonBreadCrumb to be added to the trail - * @id: optional id for the bread crumb - * @destroy: GDestroyNotify callback to be called when the bread crumb is destroyed - * - * Adds a new bread crumb to the end of the trail. - * - * Stability: Unstable - */ - -void -hildon_bread_crumb_trail_push (HildonBreadCrumbTrail *bct, - HildonBreadCrumb *item, - gpointer id, - GDestroyNotify destroy) -{ - GtkWidget *widget; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct)); - g_return_if_fail (HILDON_IS_BREAD_CRUMB (item)); - - widget = GTK_WIDGET (item); - - attach_bread_crumb (bct, widget, id, destroy); -} - -/** - * hildon_bread_crumb_trail_push_text: - * @bct: pointer to #HildonBreadCrumbTrail - * @text: content of the new bread crumb - * @id: optional id for the bread crumb - * @destroy: GDestroyNotify callback to be called when the bread crumb is destroyed - * - * Adds a new bread crumb to the end of the trail containing the specified text. - * - * Stability: Unstable - */ - -void -hildon_bread_crumb_trail_push_text (HildonBreadCrumbTrail *bct, - const gchar *text, - gpointer id, - GDestroyNotify destroy) -{ - GtkWidget *widget; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct)); - g_return_if_fail (text != NULL); - - widget = _hildon_bread_crumb_widget_new_with_text (text); - if (bct->priv->item_list == NULL) - { - g_object_set (G_OBJECT (widget), "show-separator", FALSE, NULL); - } - attach_bread_crumb (bct, widget, id, destroy); -} - -/** - * hildon_bread_crumb_trail_push_icon: - * @bct: pointer to #HildonBreadCrumbTrail - * @text: content of the new bread crumb - * @icon: a widget to set as the icon in the bread crumb - * @id: optional id for the bread crumb - * @destroy: GDestroyNotify callback to be called when the bread crumb is destroyed - * - * Adds a new bread crumb to the end of the trail containing the specified text and - * icon. - * - * Stability: Unstable - */ - -void -hildon_bread_crumb_trail_push_icon (HildonBreadCrumbTrail *bct, - const gchar *text, - GtkWidget *icon, - gpointer id, - GDestroyNotify destroy) -{ - GtkWidget *widget; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct)); - g_return_if_fail (text != NULL); - g_return_if_fail (GTK_IS_WIDGET (icon)); - - widget = _hildon_bread_crumb_widget_new_with_icon (icon, text); - if (bct->priv->item_list == NULL) - { - g_object_set (G_OBJECT (widget), "show-separator", FALSE, NULL); - } - attach_bread_crumb (bct, widget, id, destroy); -} - -/** - * hildon_bread_crumb_trail_pop: - * @bct: pointer to #HildonBreadCrumbTrail - * - * Removes the last bread crumb from the trail. - * - * Stability: Unstable - */ - -void -hildon_bread_crumb_trail_pop (HildonBreadCrumbTrail *bct) -{ - GtkWidget *child; - HildonBreadCrumbTrailPrivate *priv; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct)); - - priv = bct->priv; - - if (priv->item_list == NULL) - return; - - if (priv->item_list) - { - child = GTK_WIDGET (priv->item_list->data); - gtk_container_remove (GTK_CONTAINER (bct), child); - } - - hildon_bread_crumb_trail_update_back_button_sensitivity (bct); -} - -/** - * hildon_bread_crumb_trail_clear: - * @bct: pointer to #HildonBreadCrumbTrail - * - * Removes all the bread crumbs from the bread crumb trail. - * - * Stability: Unstable - */ - -void -hildon_bread_crumb_trail_clear (HildonBreadCrumbTrail *bct) -{ - HildonBreadCrumbTrailPrivate *priv; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct)); - - priv = bct->priv; - - while (priv->item_list) - { - hildon_bread_crumb_trail_pop (bct); - } - - /* - Sensitivity hack from hell. We need to do this while - http://bugzilla.gnome.org/show_bug.cgi?id=56070 is not - fixed to allow repeated clicking on the back button if - someone clears and rebuilds the trail when it's clicked - */ - gtk_widget_hide (priv->back_button); - gtk_widget_show (priv->back_button); -} diff --git a/hildon/hildon-bread-crumb-trail.h b/hildon/hildon-bread-crumb-trail.h deleted file mode 100644 index 71695ce..0000000 --- a/hildon/hildon-bread-crumb-trail.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2007 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * Author: Xan Lopez <xan.lopez@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_BREAD_CRUMB_TRAIL_H__ -#define __HILDON_BREAD_CRUMB_TRAIL_H__ - -#include <gtk/gtk.h> - -#include "hildon-bread-crumb.h" - -G_BEGIN_DECLS - -typedef struct _HildonBreadCrumbTrail HildonBreadCrumbTrail; -typedef struct _HildonBreadCrumbTrailClass HildonBreadCrumbTrailClass; -typedef struct _HildonBreadCrumbTrailPrivate HildonBreadCrumbTrailPrivate; - -#define HILDON_TYPE_BREAD_CRUMB_TRAIL (hildon_bread_crumb_trail_get_type ()) -#define HILDON_BREAD_CRUMB_TRAIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HILDON_TYPE_BREAD_CRUMB_TRAIL, HildonBreadCrumbTrail)) -#define HILDON_BREAD_CRUMB_TRAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HILDON_TYPE_BREAD_CRUMB_TRAIL, HildonBreadCrumbTrailClass)) -#define HILDON_IS_BREAD_CRUMB_TRAIL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HILDON_TYPE_BREAD_CRUMB_TRAIL)) -#define HILDON_IS_BREAD_CRUMB_TRAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_BREAD_CRUMB_TRAIL)) -#define HILDON_BREAD_CRUMB_TRAIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HILDON_TYPE_BREAD_CRUMB_TRAIL, HildonBreadCrumbTrailClass)) - -struct _HildonBreadCrumbTrail -{ - GtkContainer parent; - - HildonBreadCrumbTrailPrivate *priv; -}; - -struct _HildonBreadCrumbTrailClass -{ - GtkContainerClass parent_class; - - void (*crumb_clicked) (HildonBreadCrumbTrail *bct, - gpointer id); - - /* Signals used for keybindings */ - void (*move_parent) (HildonBreadCrumbTrail *bct); - - /* Padding for future expansion */ - void (*_hildon_bct_reserved1) (void); - void (*_hildon_bct_reserved2) (void); - void (*_hildon_bct_reserved3) (void); - void (*_hildon_bct_reserved4) (void); -}; - -GType hildon_bread_crumb_trail_get_type (void) G_GNUC_CONST; -GtkWidget *hildon_bread_crumb_trail_new (void); -void hildon_bread_crumb_trail_push (HildonBreadCrumbTrail *bct, HildonBreadCrumb *item, - gpointer id, GDestroyNotify destroy); -void hildon_bread_crumb_trail_push_text (HildonBreadCrumbTrail *bct, const gchar *text, - gpointer id, GDestroyNotify destroy); -void hildon_bread_crumb_trail_push_icon (HildonBreadCrumbTrail *bct, - const gchar *text, - GtkWidget *icon, - gpointer id, - GDestroyNotify destroy); -void hildon_bread_crumb_trail_pop (HildonBreadCrumbTrail *bct); -void hildon_bread_crumb_trail_clear (HildonBreadCrumbTrail *bct); - -G_END_DECLS - -#endif - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-bread-crumb-widget.c b/hildon/hildon-bread-crumb-widget.c deleted file mode 100644 index 22e4411..0000000 --- a/hildon/hildon-bread-crumb-widget.c +++ /dev/null @@ -1,517 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2007 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * Author: Xan Lopez <xan.lopez@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#undef HILDON_DISABLE_DEPRECATED - -#include "hildon-bread-crumb-widget.h" -#include "hildon-defines.h" - -#define HILDON_BREAD_CRUMB_WIDGET_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_BREAD_CRUMB_WIDGET, HildonBreadCrumbWidgetPrivate)) - -struct _HildonBreadCrumbWidgetPrivate -{ - GtkWidget *hbox; - GtkWidget *label; - GtkWidget *icon; - GtkWidget *arrow; - gchar *text; - - GtkPositionType icon_position; - gboolean constructed; - gboolean show_separator; -}; - -/* Signals */ - -enum { - LAST_SIGNAL -}; - -/* Properties */ - -enum { - PROP_0, - PROP_TEXT, - PROP_ICON, - PROP_ICON_POSITION, - PROP_SHOW_SEPARATOR -}; - -/* -static guint bread_crumb_item_signals[LAST_SIGNAL] = { 0 }; -*/ - -/* GType methods */ - -static void hildon_bread_crumb_widget_finalize (GObject *object); -static void hildon_bread_crumb_widget_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec); -static void hildon_bread_crumb_widget_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec); -static GObject* hildon_bread_crumb_widget_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_params); -static void hildon_bread_crumb_widget_set_contents (HildonBreadCrumbWidget *bread_crumb); - -static void hildon_bread_crumb_widget_clicked (GtkButton *button); - -static void hildon_bread_crumb_widget_bread_crumb_init (HildonBreadCrumbIface *iface); - -static void hildon_bread_crumb_widget_get_natural_size (HildonBreadCrumb *bread_crumb, - gint *width, - gint *height); - -G_DEFINE_TYPE_WITH_CODE (HildonBreadCrumbWidget, hildon_bread_crumb_widget, GTK_TYPE_BUTTON, - G_IMPLEMENT_INTERFACE (HILDON_TYPE_BREAD_CRUMB, - hildon_bread_crumb_widget_bread_crumb_init)) - -static void -hildon_bread_crumb_widget_class_init (HildonBreadCrumbWidgetClass *klass) -{ - GObjectClass *gobject_class = (GObjectClass*)klass; - GtkButtonClass *button_class = (GtkButtonClass*)klass; - - /* GObject signals */ - gobject_class->constructor = hildon_bread_crumb_widget_constructor; - gobject_class->finalize = hildon_bread_crumb_widget_finalize; - gobject_class->set_property = hildon_bread_crumb_widget_set_property; - gobject_class->get_property = hildon_bread_crumb_widget_get_property; - - /* GtkButton signals */ - button_class->clicked = hildon_bread_crumb_widget_clicked; - - /* Properties */ - g_object_class_install_property (gobject_class, - PROP_TEXT, - g_param_spec_string ("text", - "Text", - "Text of the label widget inside the bread crumb", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property (gobject_class, - PROP_ICON, - g_param_spec_object ("icon", - "Icon", - "Image that will appear next to the bread crumb text", - GTK_TYPE_WIDGET, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property (gobject_class, - PROP_ICON_POSITION, - g_param_spec_enum ("icon-position", - "Icon position", - "The position of the image relative to the text", - GTK_TYPE_POSITION_TYPE, - GTK_POS_LEFT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - g_object_class_install_property (gobject_class, - PROP_SHOW_SEPARATOR, - g_param_spec_boolean ("show-separator", - "Show separator", - "Show the separator attached to the item", - TRUE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /* Private data */ - g_type_class_add_private (gobject_class, sizeof (HildonBreadCrumbWidgetPrivate)); -} - -static void -hildon_bread_crumb_widget_bread_crumb_init (HildonBreadCrumbIface *iface) -{ - iface->get_natural_size = hildon_bread_crumb_widget_get_natural_size; -} - -static GObject* -hildon_bread_crumb_widget_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_params) -{ - GObject *object; - HildonBreadCrumbWidget *bread_crumb; - HildonBreadCrumbWidgetPrivate *priv; - - object = (* G_OBJECT_CLASS (hildon_bread_crumb_widget_parent_class)->constructor) (type, - n_construct_properties, - construct_params); - - bread_crumb = HILDON_BREAD_CRUMB_WIDGET (object); - priv = bread_crumb->priv; - priv->constructed = TRUE; - - priv->hbox = gtk_hbox_new (FALSE, 6); - gtk_container_add (GTK_CONTAINER (bread_crumb), priv->hbox); - - /* Separator */ - priv->arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE); - gtk_widget_set_name (priv->arrow, "hildon-bread-crumb-separator-arrow"); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->arrow, FALSE, FALSE, 0); - - if (priv->show_separator) - gtk_widget_show (priv->arrow); - - gtk_widget_set_no_show_all (priv->arrow, TRUE); - - /* Contents base container */ - bread_crumb->contents = gtk_hbox_new (FALSE, HILDON_MARGIN_DEFAULT); - gtk_container_add (GTK_CONTAINER (priv->hbox), bread_crumb->contents); - gtk_widget_show (bread_crumb->contents); - - if (priv->text || priv->icon) - hildon_bread_crumb_widget_set_contents (bread_crumb); - - /* Show everything */ - gtk_widget_show (priv->hbox); - - return object; -} - -static void -hildon_bread_crumb_widget_init (HildonBreadCrumbWidget *item) -{ - HildonBreadCrumbWidgetPrivate *priv = HILDON_BREAD_CRUMB_WIDGET_GET_PRIVATE (item); - - item->priv = priv; - - item->contents = NULL; - - priv->constructed = FALSE; - priv->text = NULL; - priv->icon = NULL; - priv->icon_position = GTK_POS_LEFT; - priv->show_separator = TRUE; -} - -static void -hildon_bread_crumb_widget_finalize (GObject *object) -{ - HildonBreadCrumbWidgetPrivate *priv = HILDON_BREAD_CRUMB_WIDGET (object)->priv; - - g_free (priv->text); - - G_OBJECT_CLASS (hildon_bread_crumb_widget_parent_class)->finalize (object); -} - -static void -hildon_bread_crumb_widget_clicked (GtkButton *button) -{ - hildon_bread_crumb_activated (HILDON_BREAD_CRUMB (button)); -} - -static void -hildon_bread_crumb_widget_set_contents (HildonBreadCrumbWidget *bread_crumb) -{ - GtkWidget *icon = NULL; - HildonBreadCrumbWidgetPrivate *priv = bread_crumb->priv; - - if (!priv->constructed) - return; - - if (!priv->text && !priv->icon) - return; - - /* If the icon exists, keep it */ - if (priv->icon) - { - icon = g_object_ref (priv->icon); - if (icon->parent) - gtk_container_remove (GTK_CONTAINER (icon->parent), icon); - priv->icon = NULL; - } - - /* Reset contents */ - if (bread_crumb->contents) - gtk_container_remove (GTK_CONTAINER (priv->hbox), - bread_crumb->contents); - - if (icon) - { - priv->icon = icon; - if (priv->icon_position == GTK_POS_LEFT || - priv->icon_position == GTK_POS_RIGHT) - bread_crumb->contents = gtk_hbox_new (FALSE, HILDON_MARGIN_DEFAULT); - else - bread_crumb->contents = gtk_vbox_new (FALSE, HILDON_MARGIN_DEFAULT); - - if (priv->icon_position == GTK_POS_LEFT || - priv->icon_position == GTK_POS_TOP) - gtk_box_pack_start (GTK_BOX (bread_crumb->contents), priv->icon, - FALSE, FALSE, 0); - else - gtk_box_pack_end (GTK_BOX (bread_crumb->contents), priv->icon, - FALSE, FALSE, 0); - - if (priv->text) - { - priv->label = gtk_label_new (priv->text); - g_object_set (G_OBJECT (priv->label), "xalign", 0.0, NULL); - gtk_label_set_ellipsize (GTK_LABEL (priv->label), - PANGO_ELLIPSIZE_END); - - if (priv->icon_position == GTK_POS_RIGHT || - priv->icon_position == GTK_POS_BOTTOM) - gtk_box_pack_start (GTK_BOX (bread_crumb->contents), priv->label, - TRUE, TRUE, 0); - else - gtk_box_pack_end (GTK_BOX (bread_crumb->contents), priv->label, - TRUE, TRUE, 0); - - } - - gtk_box_pack_start (GTK_BOX (priv->hbox), bread_crumb->contents, - TRUE, TRUE, 0); - gtk_widget_show_all (bread_crumb->contents); - - g_object_unref (icon); - } - else - { - /* Only text */ - bread_crumb->contents = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (priv->hbox), bread_crumb->contents, - TRUE, TRUE, 0); - - priv->label = gtk_label_new (priv->text); - g_object_set (G_OBJECT (priv->label), "xalign", 0.0, NULL); - gtk_label_set_ellipsize (GTK_LABEL (priv->label), - PANGO_ELLIPSIZE_END); - gtk_box_pack_start (GTK_BOX (bread_crumb->contents), priv->label, TRUE, TRUE, 0); - - gtk_widget_show_all (bread_crumb->contents); - } -} - -static void -hildon_bread_crumb_widget_set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - HildonBreadCrumbWidget *item = HILDON_BREAD_CRUMB_WIDGET (object); - - switch (prop_id) - { - case PROP_TEXT: - _hildon_bread_crumb_widget_set_text (item, g_value_get_string (value)); - break; - case PROP_ICON: - _hildon_bread_crumb_widget_set_icon (item, (GtkWidget*)g_value_get_object (value)); - break; - case PROP_ICON_POSITION: - _hildon_bread_crumb_widget_set_icon_position (item, g_value_get_enum (value)); - break; - case PROP_SHOW_SEPARATOR: - _hildon_bread_crumb_widget_set_show_separator (item, g_value_get_boolean (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_bread_crumb_widget_get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - HildonBreadCrumbWidget *item = HILDON_BREAD_CRUMB_WIDGET (object); - - switch (prop_id) - { - case PROP_TEXT: - g_value_set_string (value, item->priv->text); - break; - case PROP_ICON: - g_value_set_object (value, (GObject *)item->priv->icon); - break; - case PROP_ICON_POSITION: - g_value_set_enum (value, item->priv->icon_position); - break; - case PROP_SHOW_SEPARATOR: - g_value_set_boolean (value, item->priv->show_separator); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -void -_hildon_bread_crumb_widget_set_text (HildonBreadCrumbWidget *item, - const gchar *text) -{ - HildonBreadCrumbWidgetPrivate *priv; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_WIDGET (item)); - - priv = item->priv; - - if (priv->text) - g_free (priv->text); - - priv->text = g_strdup (text); - - hildon_bread_crumb_widget_set_contents (item); - - g_object_notify (G_OBJECT (item), "text"); -} - -const gchar* -_hildon_bread_crumb_widget_get_text (HildonBreadCrumbWidget *item) -{ - HildonBreadCrumbWidgetPrivate *priv; - - g_return_val_if_fail (HILDON_IS_BREAD_CRUMB_WIDGET (item), NULL); - - priv = item->priv; - - return priv->text; -} - -void -_hildon_bread_crumb_widget_set_show_separator (HildonBreadCrumbWidget *item, - gboolean show_separator) -{ - HildonBreadCrumbWidgetPrivate *priv; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_WIDGET (item)); - - priv = item->priv; - - if (priv->show_separator == show_separator) - return; - - priv->show_separator = show_separator; - - if (!priv->constructed) - return; - - if (show_separator) - gtk_widget_show (priv->arrow); - else - gtk_widget_hide (priv->arrow); - - g_object_notify (G_OBJECT (item), "show-separator"); -} - -static void -hildon_bread_crumb_widget_get_natural_size (HildonBreadCrumb *bread_crumb, - gint *natural_width, - gint *natural_height) -{ - GtkRequisition widget_req, label_req; - gint width, height; - PangoLayout *layout; - HildonBreadCrumbWidget *item; - HildonBreadCrumbWidgetPrivate *priv; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_WIDGET (bread_crumb)); - - item = HILDON_BREAD_CRUMB_WIDGET (bread_crumb); - priv = item->priv; - - gtk_widget_size_request (GTK_WIDGET (item), &widget_req); - - layout = gtk_widget_create_pango_layout (priv->label, priv->text); - pango_layout_get_pixel_size (layout, &width, &height); - g_object_unref (layout); - - if (natural_width) - { - *natural_width = widget_req.width; - /* Substract the size request of the label */ - gtk_widget_size_request (priv->label, &label_req); - *natural_width -= label_req.width; - - /* Add the "natural" width for the label */ - *natural_width += width; - *natural_width += GTK_CONTAINER (item)->border_width * 2; - } - - if (natural_height) - { - *natural_height = widget_req.height; - *natural_height += GTK_CONTAINER (item)->border_width * 2; - } -} - -GtkWidget* -_hildon_bread_crumb_widget_new () -{ - return GTK_WIDGET (g_object_new (HILDON_TYPE_BREAD_CRUMB_WIDGET, NULL)); -} - -GtkWidget* -_hildon_bread_crumb_widget_new_with_text (const gchar *text) -{ - return GTK_WIDGET (g_object_new (HILDON_TYPE_BREAD_CRUMB_WIDGET, - "text", text, - NULL)); -} - -GtkWidget* -_hildon_bread_crumb_widget_new_with_icon (GtkWidget *icon, const gchar *text) -{ - return GTK_WIDGET (g_object_new (HILDON_TYPE_BREAD_CRUMB_WIDGET, - "icon", icon, - "text", text, - NULL)); -} - -void -_hildon_bread_crumb_widget_set_icon (HildonBreadCrumbWidget *bread_crumb, - GtkWidget *icon) -{ - HildonBreadCrumbWidgetPrivate *priv; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_WIDGET (bread_crumb)); - - priv = bread_crumb->priv; - - priv->icon = icon; - - hildon_bread_crumb_widget_set_contents (bread_crumb); - - g_object_notify (G_OBJECT (bread_crumb), "icon"); -} - -void -_hildon_bread_crumb_widget_set_icon_position (HildonBreadCrumbWidget *bread_crumb, - GtkPositionType icon_position) -{ - HildonBreadCrumbWidgetPrivate *priv; - - g_return_if_fail (HILDON_IS_BREAD_CRUMB_WIDGET (bread_crumb)); - - priv = bread_crumb->priv; - - if (priv->icon_position == icon_position) - return; - - priv->icon_position = icon_position; - - hildon_bread_crumb_widget_set_contents (bread_crumb); - - g_object_notify (G_OBJECT (bread_crumb), "icon-position"); -} diff --git a/hildon/hildon-bread-crumb-widget.h b/hildon/hildon-bread-crumb-widget.h deleted file mode 100644 index 4c04c23..0000000 --- a/hildon/hildon-bread-crumb-widget.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2007 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * Author: Xan Lopez <xan.lopez@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_BREAD_CRUMB_WIDGET_H__ -#define __HILDON_BREAD_CRUMB_WIDGET_H__ - -#include <gtk/gtk.h> - -#include "hildon-bread-crumb.h" - -G_BEGIN_DECLS - -typedef struct _HildonBreadCrumbWidget HildonBreadCrumbWidget; -typedef struct _HildonBreadCrumbWidgetClass HildonBreadCrumbWidgetClass; -typedef struct _HildonBreadCrumbWidgetPrivate HildonBreadCrumbWidgetPrivate; - -#define HILDON_TYPE_BREAD_CRUMB_WIDGET (hildon_bread_crumb_widget_get_type ()) -#define HILDON_BREAD_CRUMB_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HILDON_TYPE_BREAD_CRUMB_WIDGET, HildonBreadCrumbWidget)) -#define HILDON_BREAD_CRUMB_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), HILDON_TYPE_BREAD_CRUMB_WIDGET, HildonBreadCrumbWidgetClass)) -#define HILDON_IS_BREAD_CRUMB_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HILDON_TYPE_BREAD_CRUMB_WIDGET)) -#define HILDON_IS_BREAD_CRUMB_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_BREAD_CRUMB_WIDGET)) -#define HILDON_BREAD_CRUMB_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), HILDON_TYPE_BREAD_CRUMB_WIDGET, HildonBreadCrumbWidgetClass)) - -struct _HildonBreadCrumbWidget -{ - GtkButton parent; - - GtkWidget *contents; - - HildonBreadCrumbWidgetPrivate *priv; -}; - -struct _HildonBreadCrumbWidgetClass -{ - GtkButtonClass parent_class; -}; - -GType hildon_bread_crumb_widget_get_type (void) G_GNUC_CONST; -GtkWidget *_hildon_bread_crumb_widget_new (void); -GtkWidget *_hildon_bread_crumb_widget_new_with_text (const gchar *label); -GtkWidget *_hildon_bread_crumb_widget_new_with_icon (GtkWidget *icon, const gchar *text); -void _hildon_bread_crumb_widget_set_text (HildonBreadCrumbWidget *item, const gchar *text); -const gchar *_hildon_bread_crumb_widget_get_text (HildonBreadCrumbWidget *item); -void _hildon_bread_crumb_widget_set_show_separator (HildonBreadCrumbWidget *item, - gboolean show_separator); -void _hildon_bread_crumb_widget_set_icon (HildonBreadCrumbWidget *bread_crumb_widget, - GtkWidget *icon); -void _hildon_bread_crumb_widget_set_icon_position (HildonBreadCrumbWidget *bread_crumb, - GtkPositionType icon_position); - -G_END_DECLS - -#endif - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-bread-crumb.c b/hildon/hildon-bread-crumb.c deleted file mode 100644 index d59bddf..0000000 --- a/hildon/hildon-bread-crumb.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2007 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * Author: Xan Lopez <xan.lopez@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-bread-crumb - * @short_description: Interface for elements in a #HildonBreadCrumbTrail - * - * #HildonBreadCrumb is an interface for creating new types of items - * for the #HildonBreadCrumbTrail widget. - * - * #HildonBreadCrumb is deprecated since hildon 2.2. You should instead use - * #HildonStackableWindow to represent hierarchical structure in - * applications. - */ - -#undef HILDON_DISABLE_DEPRECATED - -#include "hildon-bread-crumb.h" - -static void hildon_bread_crumb_base_init (gpointer g_class); - -GType -hildon_bread_crumb_get_type (void) -{ - static GType bread_crumb_type = 0; - - if (G_UNLIKELY (bread_crumb_type == 0)) - { - const GTypeInfo bread_crumb_info = - { - sizeof (HildonBreadCrumbIface), /* class_size */ - hildon_bread_crumb_base_init, /* base_init */ - NULL, /* base_finalize */ - NULL, - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, - 0, - NULL - }; - - bread_crumb_type = - g_type_register_static (G_TYPE_INTERFACE, "HildonBreadCrumb", - &bread_crumb_info, 0); - - g_type_interface_add_prerequisite (bread_crumb_type, GTK_TYPE_WIDGET); - } - - return bread_crumb_type; -} - -static void -hildon_bread_crumb_base_init (gpointer g_class) -{ - static gboolean initialized = FALSE; - - if (initialized == FALSE) - { - g_signal_new ("crumb-activated", - HILDON_TYPE_BREAD_CRUMB, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HildonBreadCrumbIface, crumb_activated), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - initialized = TRUE; - } -} - -/** - * hildon_bread_crumb_get_natural_size: - * @bread_crumb: A #HildonBreadCrumb - * @width: location to store the natural width request of the @bread_crumb - * @height: location to store the natural height request of the @bread_crumb - * - * Function to ask the @bread_crumb its preferred width and height requisition. - * Natural size is different to size_request in that it's not the minimum space - * the widget needs, but the ideal space it'd like to be allocated. For example, - * in the case of a label the natural size would be the width and height needed - * to show the full label without line breaks. - * - **/ - -void -hildon_bread_crumb_get_natural_size (HildonBreadCrumb *bread_crumb, - gint *width, - gint *height) -{ - g_return_if_fail (HILDON_IS_BREAD_CRUMB (bread_crumb)); - - (* HILDON_BREAD_CRUMB_GET_IFACE (bread_crumb)->get_natural_size) (bread_crumb, width, height); -} - -/** - * hildon_bread_crumb_activated: - * @bread_crumb: a #HildonBreadCrumb - * - * Emits the "crumb-activated" signal. The signal is meant to indicate that - * the user has interacted with the bread crumb. - **/ - -void -hildon_bread_crumb_activated (HildonBreadCrumb *bread_crumb) -{ - g_return_if_fail (HILDON_IS_BREAD_CRUMB (bread_crumb)); - - g_signal_emit_by_name (bread_crumb, "crumb-activated"); -} - - diff --git a/hildon/hildon-bread-crumb.h b/hildon/hildon-bread-crumb.h deleted file mode 100644 index 8ce0c83..0000000 --- a/hildon/hildon-bread-crumb.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2007 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * Author: Xan Lopez <xan.lopez@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_BREAD_CRUMB_H__ -#define __HILDON_BREAD_CRUMB_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -typedef struct _HildonBreadCrumb HildonBreadCrumb; -typedef struct _HildonBreadCrumbIface HildonBreadCrumbIface; - -#define HILDON_TYPE_BREAD_CRUMB (hildon_bread_crumb_get_type ()) -#define HILDON_BREAD_CRUMB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HILDON_TYPE_BREAD_CRUMB, HildonBreadCrumb)) -#define HILDON_BREAD_CRUMB_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), HILDON_TYPE_BREAD_CRUMB, HildonBreadCrumbIface)) -#define HILDON_IS_BREAD_CRUMB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HILDON_TYPE_BREAD_CRUMB)) -#define HILDON_BREAD_CRUMB_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), HILDON_TYPE_BREAD_CRUMB, HildonBreadCrumbIface)) - -struct _HildonBreadCrumbIface -{ - GTypeInterface g_iface; - - /* virtual table */ - void (* get_natural_size) (HildonBreadCrumb *bread_crumb, - gint *natural_width, gint *natural_height); - /* signals */ - void (* crumb_activated) (HildonBreadCrumb *bread_crumb); -}; - -GType hildon_bread_crumb_get_type (void) G_GNUC_CONST; -void hildon_bread_crumb_get_natural_size (HildonBreadCrumb *bread_crumb, - gint *width, gint *height); -void hildon_bread_crumb_activated (HildonBreadCrumb *bread_crumb); - -G_END_DECLS - -#endif - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-calendar-popup-private.h b/hildon/hildon-calendar-popup-private.h deleted file mode 100644 index b237576..0000000 --- a/hildon/hildon-calendar-popup-private.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_CALENDAR_POPUP_PRIVATE_H__ -#define __HILDON_CALENDAR_POPUP_PRIVATE_H__ - -#include <gtk/gtkdialog.h> - -G_BEGIN_DECLS - -typedef struct _HildonCalendarPopupPrivate HildonCalendarPopupPrivate; - -#define HILDON_CALENDAR_POPUP_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), HILDON_TYPE_CALENDAR_POPUP, HildonCalendarPopupPrivate)); - -struct _HildonCalendarPopupPrivate -{ - GtkWidget *cal; -}; - -G_END_DECLS - -#endif /* __HILDON_CALENDAR_POPUP_PRIVATE_H__ */ diff --git a/hildon/hildon-calendar-popup.c b/hildon/hildon-calendar-popup.c deleted file mode 100644 index 607008b..0000000 --- a/hildon/hildon-calendar-popup.c +++ /dev/null @@ -1,529 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-calendar-popup - * @short_description: CalendarPopup allows choosing a date from a popup calendar. - * @see_also: #HildonDateEditor, #HildonTimeEditor - * - * HildonCalendarPopup is a dialog which contains a HildonCalendar. It - * also contains arrow buttons for changing the month/year. If an - * entered date is invalid, an information message will be shown. - * - * <note> - * <para> - * #HildonCalendarPopup has been deprecated since Hildon 2.2 and should not - * be used in newly written code. - * See <link linkend="hildon-migrating-date-widgets">Migrating Date Widgets</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <title>HildonCalendarPopup example</title> - * <programlisting> - * ... - * gint y, m, d; - * GtkWidget *parent, *popup; - * <!-- --> - * // get current date into &y, &m, &d... - * <!-- --> - * gtk_widget_get_ancestor (GTK_WIDGET (data), GTK_TYPE_WINDOW); - * popup = hildon_calendar_popup_new (GTK_WINDOW (parent), y, m, d); - * <!-- --> - * result = gtk_dialog_run (GTK_DIALOG (popup)); - * switch (result) - * { - * case GTK_RESPONSE_OK: - * case GTK_RESPONSE_ACCEPT: - * <!-- --> - * hildon_calendar_popup_get_date (HILDON_CALENDAR_POPUP (popup), &y, &m, &d); - * <!-- --> - * // here set the new date - * } - * gtk_widget_destroy(popup); - * ... - * </programlisting> - * </example> - * - */ - - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <langinfo.h> -#include <time.h> -#include <libintl.h> - -#include <gtk/gtk.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-calendar-popup.h" -#include "hildon-calendar-popup-private.h" -#include "hildon-calendar.h" -#include "hildon-stock.h" - -#define _(String)\ - dgettext("hildon-libs", String) - -static void -init_dmy (guint year, - guint month, - guint day, - guint *d, - guint *m, - guint * y); - -static void -hildon_calendar_popup_class_init (HildonCalendarPopupClass *cal_class); - -static void -hildon_calendar_popup_init (HildonCalendarPopup *cal); - -static void -hildon_calendar_selected_date (GtkWidget *self, - gpointer cal_popup); - -static gboolean -hildon_key_pressed (GtkWidget *widget, - GdkEventKey *event, - gpointer cal_popup); - -static void -hildon_calendar_popup_set_property (GObject *object, - guint property_id, - const GValue * value, - GParamSpec * pspec); -static void -hildon_calendar_popup_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static GtkDialog* parent_class; - -enum -{ - PROP_0, - PROP_DAY, - PROP_MONTH, - PROP_YEAR, - PROP_MIN_YEAR, - PROP_MAX_YEAR -}; - -GType G_GNUC_CONST -hildon_calendar_popup_get_type (void) -{ - static GType popup_type = 0; - - if (!popup_type) { - static const GTypeInfo popup_info = { - sizeof (HildonCalendarPopupClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_calendar_popup_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonCalendarPopup), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_calendar_popup_init, - }; - popup_type = g_type_register_static (GTK_TYPE_DIALOG, - "HildonCalendarPopup", - &popup_info, 0); - } - - return popup_type; -} - -/** - * hildon_calendar_popup_new: - * @parent: parent window for dialog - * @year: initial year - * @month: initial month - * @day: initial day - * - * This function returns a new HildonCalendarPopup. The initially - * selected date is specified by the parameters (year, month, day). - * If the specified date is invalid, the current date is used. - * - * Returns: new @HildonCalendarPopup widget - */ -GtkWidget* -hildon_calendar_popup_new (GtkWindow *parent, - guint year, - guint month, - guint day) -{ - HildonCalendarPopup *cal = NULL; - - /* Create new HildonCalendarPopup */ - cal = HILDON_CALENDAR_POPUP (g_object_new (HILDON_TYPE_CALENDAR_POPUP, - "year", year, "month", month, "day", day, - NULL)); - - if (parent) { - gtk_window_set_transient_for (GTK_WINDOW(cal), parent); - } - - return GTK_WIDGET (cal); -} - -/** - * hildon_calendar_popup_set_date: - * @cal: the @HildonCalendarPopup widget - * @year: year - * @month: month - * @day: day - * - * Activates a new date on the calendar popup. - **/ -void -hildon_calendar_popup_set_date (HildonCalendarPopup *cal, - guint year, - guint month, - guint day) -{ - guint dtmp, mtmp, ytmp = 0; - HildonCalendarPopupPrivate *priv; - - g_return_if_fail (HILDON_IS_CALENDAR_POPUP (cal)); - - priv = HILDON_CALENDAR_POPUP_GET_PRIVATE (cal); - g_assert (priv); - - /* Choose current date if the date is invalid: */ - init_dmy (year, month, day, &dtmp, &mtmp, &ytmp); - - /* Remove all visual markers */ - hildon_calendar_clear_marks (HILDON_CALENDAR (priv->cal)); - - /* Set a new date */ - hildon_calendar_select_month (HILDON_CALENDAR (priv->cal), mtmp - 1, ytmp); - hildon_calendar_select_day (HILDON_CALENDAR (priv->cal), dtmp); -} - -/** - * hildon_calendar_popup_get_date: - * @cal: the @HildonCalendarPopup widget - * @year: year - * @month: month - * @day: day - * - * Gets the currently selected year, month, and day. - * It's possible to pass NULL to any of the pointers if you don't need that data. - */ -void -hildon_calendar_popup_get_date (HildonCalendarPopup *cal, - guint *year, - guint *month, - guint *day) -{ - HildonCalendarPopupPrivate *priv; - - g_return_if_fail (HILDON_IS_CALENDAR_POPUP (cal)); - - priv = HILDON_CALENDAR_POPUP_GET_PRIVATE (cal); - g_assert (priv); - - hildon_calendar_get_date (HILDON_CALENDAR (priv->cal), year, month, day); - if (month != NULL) - *month = *month + 1; - - if (day != NULL && - month != NULL && - year != NULL && - ! g_date_valid_dmy (*day, *month, *year)) - *day = g_date_get_days_in_month (*month, *year); -} - -static void -hildon_calendar_popup_class_init (HildonCalendarPopupClass *cal_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (cal_class); - parent_class = g_type_class_peek_parent (cal_class); - - object_class->set_property = hildon_calendar_popup_set_property; - object_class->get_property = hildon_calendar_popup_get_property; - - g_type_class_add_private(cal_class, sizeof (HildonCalendarPopupPrivate)); - - /* Install new properties for the GObject_class */ - - g_object_class_install_property (object_class, PROP_MIN_YEAR, - g_param_spec_uint ("min-year", - "Minimum valid year", - "Minimum valid year", - 1, 10000, - 1970, - G_PARAM_WRITABLE)); - - g_object_class_install_property (object_class, PROP_MAX_YEAR, - g_param_spec_uint ("max-year", - "Maximum valid year", - "Maximum valid year", - 1, 10000, - 2037, - G_PARAM_WRITABLE)); - - g_object_class_install_property (object_class, PROP_DAY, - g_param_spec_int ("day", - "Day", - "currently selected day", - G_MININT, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, PROP_MONTH, - g_param_spec_int ("month", - "Month", - "currently selected month", - G_MININT, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, PROP_YEAR, - g_param_spec_int ("year", - "Year", - "the currently selected year", - G_MININT, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - -} - -static void -hildon_calendar_popup_init (HildonCalendarPopup *cal) -{ - HildonCalendarPopupPrivate *priv; - static int set_domain = 1; - - priv = HILDON_CALENDAR_POPUP_GET_PRIVATE(cal); - g_assert (priv); - - /* set the domain directory for different language */ - /* FIXME I can't exactly figure out why is this here... */ - if (set_domain) { - (void) bindtextdomain ("hildon-libs", LOCALEDIR); - set_domain = 0; - } - - priv->cal = hildon_calendar_new (); - - /* dialog options and packing */ - hildon_calendar_set_display_options (HILDON_CALENDAR (priv->cal), - HILDON_CALENDAR_SHOW_HEADING | - HILDON_CALENDAR_SHOW_DAY_NAMES | - HILDON_CALENDAR_SHOW_WEEK_NUMBERS); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (cal)->vbox), priv->cal, - TRUE, TRUE, 0); - gtk_dialog_set_has_separator (GTK_DIALOG (cal), FALSE); - gtk_dialog_add_button (GTK_DIALOG (cal), HILDON_STOCK_DONE, GTK_RESPONSE_OK); - gtk_widget_show(priv->cal); - - /* Connect signals */ - g_signal_connect (G_OBJECT (priv->cal), "key-press-event", - G_CALLBACK (hildon_key_pressed), cal); - - g_signal_connect (G_OBJECT (priv->cal), "selected_date", - G_CALLBACK (hildon_calendar_selected_date), cal); - - /* set decorations, needs realizing first */ - /* FIXME That should be moved to on_realize */ - gtk_widget_realize (GTK_WIDGET (cal)); - gdk_window_set_decorations (GTK_WIDGET (cal)->window, GDK_DECOR_BORDER); -} - -/* - * Signal handler for key-press-event. Closes the dialog for some - * special keys. - */ -static gboolean -hildon_key_pressed (GtkWidget *widget, - GdkEventKey *event, - gpointer cal_popup) -{ - g_assert (HILDON_IS_CALENDAR_POPUP (cal_popup)); - - /* Handle Return key press as OK response */ - if (event->keyval == GDK_Return) - { - gtk_dialog_response (GTK_DIALOG (cal_popup), GTK_RESPONSE_OK); - return TRUE; - } - - /* Handle Esc key press as CANCEL response */ - if ((event->keyval == GDK_Escape)) - { - gtk_dialog_response (GTK_DIALOG (cal_popup), GTK_RESPONSE_CANCEL); - return TRUE; - } - - return FALSE; -} - -/* - * Validates the given date or initializes it with the current date - */ -static void -init_dmy (guint year, - guint month, - guint day, - guint *d, - guint *m, - guint *y) -{ - g_assert (d != NULL); - g_assert (m != NULL); - g_assert (y != NULL); - - GDate date; - - /* Initialize the date with a valid selected date */ - if (g_date_valid_dmy (day, month, year)) { - *d = day; - *m = month; - *y = year; - } else { - - /* If selected date is invalid initialize the date with current date */ - g_date_clear (&date, 1); - g_date_set_time (&date, time (NULL)); - - *d = g_date_get_day (&date); - *m = g_date_get_month (&date); - *y = g_date_get_year (&date); - } -} - -/* - * Exits the dialog when "selected_date" signal is emmited. */ -static void -hildon_calendar_selected_date (GtkWidget *self, - gpointer cal_popup) -{ - g_assert (GTK_IS_WIDGET (self)); - g_assert (HILDON_IS_CALENDAR_POPUP (cal_popup)); - - gtk_dialog_response (GTK_DIALOG (cal_popup), GTK_RESPONSE_OK); -} - - -static void -hildon_calendar_popup_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonCalendarPopup *popup = HILDON_CALENDAR_POPUP (object); - - HildonCalendarPopupPrivate *priv = - HILDON_CALENDAR_POPUP_GET_PRIVATE(HILDON_CALENDAR_POPUP (object)); - g_assert (priv); - - switch (property_id) { - - case PROP_DAY: - { - guint year, month, day = 0; - hildon_calendar_popup_get_date (popup, &year, &month, &day); - - /*Verifies that the date is valid: */ - hildon_calendar_popup_set_date (popup, year, month, g_value_get_int (value)); - break; - } - - case PROP_MONTH: - { - guint year, month, day = 0; - hildon_calendar_popup_get_date (popup, &year, &month, &day); - - /*Verifies that the date is valid: */ - hildon_calendar_popup_set_date (popup, year, g_value_get_int (value), day); - break; - } - - case PROP_YEAR: - { - guint year, month, day = 0; - hildon_calendar_popup_get_date (popup, &year, &month, &day); - - /*Verifies that the date is valid: */ - hildon_calendar_popup_set_date (popup, g_value_get_int (value), month, day); - break; - } - - case PROP_MIN_YEAR: - g_object_set_property (G_OBJECT (priv->cal), "min-year", value); - break; - - case PROP_MAX_YEAR: - g_object_set_property (G_OBJECT (priv->cal), "max-year", value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -hildon_calendar_popup_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - HildonCalendarPopupPrivate *priv = - HILDON_CALENDAR_POPUP_GET_PRIVATE (HILDON_CALENDAR_POPUP (object)); - g_assert (priv); - - switch (property_id) { - - case PROP_DAY: - g_object_get_property (G_OBJECT (priv->cal), pspec->name, value); - break; - - case PROP_MONTH: - g_object_get_property (G_OBJECT (priv->cal), pspec->name, value); - break; - - case PROP_YEAR: - g_object_get_property (G_OBJECT (priv->cal), pspec->name, value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - diff --git a/hildon/hildon-calendar-popup.h b/hildon/hildon-calendar-popup.h deleted file mode 100644 index a6aab4a..0000000 --- a/hildon/hildon-calendar-popup.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_CALENDAR_POPUP_H__ -#define __HILDON_CALENDAR_POPUP_H__ - -#include <gtk/gtkdialog.h> - -G_BEGIN_DECLS - -typedef struct _HildonCalendarPopup HildonCalendarPopup; - -typedef struct _HildonCalendarPopupClass HildonCalendarPopupClass; - -#define HILDON_TYPE_CALENDAR_POPUP \ - (hildon_calendar_popup_get_type()) - -#define HILDON_CALENDAR_POPUP(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_CALENDAR_POPUP, HildonCalendarPopup)) - -#define HILDON_CALENDAR_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \ - HILDON_TYPE_CALENDAR_POPUP, HildonCalendarPopupClass)) - -#define HILDON_IS_CALENDAR_POPUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj,\ - HILDON_TYPE_CALENDAR_POPUP)) - -#define HILDON_IS_CALENDAR_POPUP_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_CALENDAR_POPUP)) - -#define HILDON_CALENDAR_POPUP_GET_CLASS(obj) \ - ((HildonCalendarPopupClass *) G_OBJECT_GET_CLASS(obj)) - -struct _HildonCalendarPopup -{ - GtkDialog parent; -}; - -struct _HildonCalendarPopupClass -{ - GtkDialogClass parent_class; -}; - -GType G_GNUC_CONST -hildon_calendar_popup_get_type (void); - -GtkWidget* -hildon_calendar_popup_new (GtkWindow *parent, - guint year, - guint month, - guint day); - -void -hildon_calendar_popup_set_date (HildonCalendarPopup *cal, - guint year, - guint month, - guint day); - -void -hildon_calendar_popup_get_date (HildonCalendarPopup *cal, - guint *year, - guint *month, - guint *day); - -G_END_DECLS - -#endif /* __HILDON_CALENDAR_POPUP_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-calendar-private.h b/hildon/hildon-calendar-private.h deleted file mode 100644 index 4d01ac4..0000000 --- a/hildon/hildon-calendar-private.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_CALENDAR_PRIVATE_H__ -#define __HILDON_CALENDAR_PRIVATE_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_CALENDAR_GET_PRIVATE(widget) \ - (((HildonCalendarPrivate*)(HILDON_CALENDAR (widget)->private_data))) - -typedef struct _HildonCalendarPrivate HildonCalendarPrivate; - -struct _HildonCalendarPrivate -{ - GdkWindow *header_win; - GdkWindow *footer_win; - GdkWindow *day_name_win; - GdkWindow *main_win; - GdkWindow *week_win; - GdkWindow *arrow_win[4]; - - gint year_before; - guint header_h; - guint day_name_h; - guint main_h; - - guint arrow_state[4]; - /* guint arrow_width; This is now defined constant. Even normal Gtk don't allow to change this */ - guint arrow_width; - guint max_month_width; - guint max_year_width; - - guint day_width; - guint week_width; - - guint min_day_width; - guint max_day_char_width; - guint max_day_char_ascent; - guint max_day_char_descent; - guint max_label_char_ascent; - guint max_label_char_descent; - guint max_week_char_width; - - guint freeze_count; - - /* flags */ - guint dirty_header : 1; - guint dirty_day_names : 1; - guint dirty_main : 1; - guint dirty_week : 1; - - /* guint year_before : 1;*/ - - guint need_timer : 1; - - guint in_drag : 1; - guint drag_highlight : 1; - - guint32 timer; - gint click_child; - - /* Following variables are for current date */ - guint current_day; - guint current_month; - guint current_year; - - /* Keep track of day and month - * where mouse button was pressed - */ - guint pressed_day; - guint pressed_month; - - /* Boolean value to indicate if - * out of bound day was selected - */ - gboolean is_bad_day; - - /* Must check if we are sliding stylus */ - gboolean slide_stylus; - gint prev_row; - gint prev_col; - - gint week_start; - - gint drag_start_x; - gint drag_start_y; - - gint min_year; - gint max_year; - - char *abbreviated_dayname[7]; - char *monthname[12]; -}; - -G_END_DECLS - -#endif /* __HILDON_CALENDAR_PRIVATE_H__ */ diff --git a/hildon/hildon-calendar.c b/hildon/hildon-calendar.c deleted file mode 100644 index b460e50..0000000 --- a/hildon/hildon-calendar.c +++ /dev/null @@ -1,4303 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * GTK Calendar Widget - * Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson and Mattias Groenlund - * - * lib_date routines - * Copyright (C) 1995, 1996, 1997, 1998 by Steffen Beyer - * - * HldonCalendar modifications - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -/** - * SECTION:hildon-calendar - * @short_description: A calendar widget - * - * #HildonCalendar is a slightly modified #GtkCalendar. It has an almost same API - * but a slightly different look and behaviour. Use this widget instead of - * standard #GtkCalendar or use #HildonDateEditor for more higher-level date setting - * operations. - * - * <note> - * <para> - * #HildonCalendar has been deprecated since Hildon 2.2 - * See <link linkend="hildon-migrating-date-widgets">Migrating Date Widgets</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#define _GNU_SOURCE /* needed for GNU nl_langinfo_l */ - -#include <locale.h> - -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -#include <string.h> -#include <stdlib.h> -#include <time.h> -#include <langinfo.h> - -#include <glib/gprintf.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtkprivate.h> - -#include "hildon-calendar.h" -#include "hildon-marshalers.h" -#include "hildon-calendar-private.h" - -/***************************************************************************/ -/* The following date routines are taken from the lib_date package. Keep - * them separate in case we want to update them if a newer lib_date comes - * out with fixes. */ - -typedef unsigned int N_int; - -typedef unsigned long N_long; - -typedef signed long Z_long; - -typedef enum { false = FALSE , true = TRUE } boolean; - -#define and && /* logical (boolean) operators: lower case */ - -#define or || - -static const N_int month_length [2][13] = -{ - { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } -}; - -static const N_int days_in_months[2][14] = -{ - { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, - { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } -}; - -static Z_long calc_days (N_int year, N_int mm, N_int dd); - -static N_int day_of_week (N_int year, N_int mm, N_int dd); - -static Z_long dates_difference (N_int year1, N_int mm1, N_int dd1, - N_int year2, N_int mm2, N_int dd2); - -static N_int weeks_in_year (N_int year); - -static boolean -leap (N_int year) -{ - return ((((year % 4) == 0) and ((year % 100) != 0)) or ((year % 400) == 0)); -} - -static N_int -day_of_week (N_int year, - N_int mm, - N_int dd) -{ - Z_long days; - - days = calc_days (year, mm, dd); - if (days > 0L) - { - days--; - days %= 7L; - days++; - } - return( (N_int) days ); -} - -static N_int -weeks_in_year (N_int year) -{ - return (52 + ((day_of_week(year,1,1)==4) or (day_of_week(year,12,31)==4))); -} - -static boolean -check_date (N_int year, - N_int mm, - N_int dd) -{ - if (year < 1) return(false); - if ((mm < 1) or (mm > 12)) return(false); - if ((dd < 1) or (dd > month_length[leap(year)][mm])) return(false); - return(true); -} - -static N_int -week_number (N_int year, - N_int mm, - N_int dd) -{ - N_int first; - - first = day_of_week (year,1,1) - 1; - return( (N_int) ( (dates_difference(year,1,1, year,mm,dd) + first) / 7L ) + - (first < 4) ); -} - -static Z_long -year_to_days (N_int year) -{ - return ( year * 365L + (year / 4) - (year / 100) + (year / 400) ); -} - -static Z_long -calc_days (N_int year, - N_int mm, - N_int dd) -{ - boolean lp; - - if (year < 1) return(0L); - if ((mm < 1) or (mm > 12)) return(0L); - if ((dd < 1) or (dd > month_length[(lp = leap(year))][mm])) return(0L); - return( year_to_days(--year) + days_in_months[lp][mm] + dd ); -} - -static boolean -week_of_year (N_int *week, - N_int *year, - N_int mm, - N_int dd) -{ - if (check_date(*year,mm,dd)) - { - *week = week_number(*year,mm,dd); - if (*week == 0) - *week = weeks_in_year(--(*year)); - else if (*week > weeks_in_year(*year)) - { - *week = 1; - (*year)++; - } - return(true); - } - return(false); -} - -static Z_long -dates_difference (N_int year1, - N_int mm1, - N_int dd1, - N_int year2, - N_int mm2, - N_int dd2) -{ - return (calc_days (year2, mm2, dd2) - calc_days (year1, mm1, dd1)); -} - -/*** END OF lib_date routines ********************************************/ - -/* HILDON: Spacings modified */ -#define HILDON_ARROW_SEP 5 /* Space between arrows and data */ - -#define HILDON_DAY_WIDTH 26 - -#define HILDON_DAY_HEIGHT 25 - -/* additional widths given to week number and day windows */ - -#define HILDON_WEEKS_EXTRA_WIDTH 8 - -#define HILDON_DAYS_EXTRA_WIDTH 8 - -/* Spacing around day/week headers and main area, inside those windows */ - -#define CALENDAR_MARGIN 0 - -/* Spacing around day/week headers and main area, outside those windows */ - -#define INNER_BORDER 0 /* 4 */ - -/* Separation between day headers and main area */ - -#define CALENDAR_YSEP 3 /* 4 */ - -/* Separation between week headers and main area */ - -#define CALENDAR_XSEP 6 /* 4 */ - -#define DAY_XSEP 0 /* not really good for small calendar */ - -#define DAY_YSEP 0 /* not really good for small calendar */ - -/* Color usage */ -#define HEADER_FG_COLOR(widget) \ - (& (widget)->style->fg[GTK_WIDGET_STATE (widget)]) - -#define HEADER_BG_COLOR(widget) \ - (& (widget)->style->bg[GTK_WIDGET_STATE (widget)]) - -#define SELECTED_BG_COLOR(widget) \ - (& (widget)->style->base[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]) - -#define SELECTED_FG_COLOR(widget) \ - (& (widget)->style->text[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]) - -#define NORMAL_DAY_COLOR(widget) \ - (& (widget)->style->fg[GTK_WIDGET_STATE (widget)]) - -#define PREV_MONTH_COLOR(widget) \ - (& (widget)->style->mid[GTK_WIDGET_STATE (widget)]) - -#define NEXT_MONTH_COLOR(widget) \ - (& (widget)->style->mid[GTK_WIDGET_STATE (widget)]) - -#define MARKED_COLOR(widget) \ - (& (widget)->style->fg[GTK_WIDGET_STATE (widget)]) - -#define BACKGROUND_COLOR(widget) \ - (& (widget)->style->base[GTK_WIDGET_STATE (widget)]) - -#define HIGHLIGHT_BACK_COLOR(widget) \ - (& (widget)->style->mid[GTK_WIDGET_STATE (widget)]) - -#define CALENDAR_INITIAL_TIMER_DELAY 200 - -#define CALENDAR_TIMER_DELAY 20 - -enum { - ARROW_YEAR_LEFT, - ARROW_YEAR_RIGHT, - ARROW_MONTH_LEFT, - ARROW_MONTH_RIGHT -}; - -enum { - MONTH_PREV, - MONTH_CURRENT, - MONTH_NEXT -}; - -enum { - MONTH_CHANGED_SIGNAL, - DAY_SELECTED_SIGNAL, - DAY_SELECTED_DOUBLE_CLICK_SIGNAL, - PREV_MONTH_SIGNAL, - NEXT_MONTH_SIGNAL, - PREV_YEAR_SIGNAL, - NEXT_YEAR_SIGNAL, - ERRONEOUS_DATE_SIGNAL, - SELECTED_DATE_SIGNAL, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_YEAR, - PROP_MONTH, - PROP_DAY, - PROP_SHOW_HEADING, - PROP_SHOW_DAY_NAMES, - PROP_NO_MONTH_CHANGE, - PROP_SHOW_WEEK_NUMBERS, - PROP_WEEK_START, - PROP_MIN_YEAR, - PROP_MAX_YEAR, - PROP_LAST -}; - -static gint hildon_calendar_signals [LAST_SIGNAL] = { 0 }; - -static GtkWidgetClass* parent_class = NULL; - -typedef void (*HildonCalendarSignalDate) (GtkObject *object, guint arg1, guint arg2, guint arg3, gpointer data); - -static void -hildon_calendar_class_init (HildonCalendarClass *class); - -static void -hildon_calendar_init (HildonCalendar *calendar); - -static void -hildon_calendar_finalize (GObject *calendar); - -static void -hildon_calendar_destroy (GtkObject *calendar); - -static void -hildon_calendar_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_calendar_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static void -hildon_calendar_realize (GtkWidget *widget); - -static void -hildon_calendar_unrealize (GtkWidget *widget); - -static void -hildon_calendar_size_request (GtkWidget *widget, - GtkRequisition *requisition); - -static void -hildon_calendar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static gint -hildon_calendar_expose (GtkWidget *widget, - GdkEventExpose *event); - -static gint -hildon_calendar_button_press (GtkWidget *widget, - GdkEventButton *event); - -static gint -hildon_calendar_button_release (GtkWidget *widget, - GdkEventButton *event); - -static void -hildon_calendar_main_button (GtkWidget *widget, - GdkEventButton *event); - -static gint -hildon_calendar_motion_notify (GtkWidget *widget, - GdkEventMotion *event); - -static gint -hildon_calendar_enter_notify (GtkWidget *widget, - GdkEventCrossing *event); - -static gint -hildon_calendar_leave_notify (GtkWidget *widget, - GdkEventCrossing *event); - -static gint -hildon_calendar_key_press (GtkWidget *widget, - GdkEventKey *event); - -static gint -hildon_calendar_scroll (GtkWidget *widget, - GdkEventScroll *event); - -static void -hildon_calendar_grab_notify (GtkWidget *widget, - gboolean was_grabbed); - -static gboolean -hildon_calendar_focus_out (GtkWidget *widget, - GdkEventFocus *event); - -static void -hildon_calendar_state_changed (GtkWidget *widget, - GtkStateType previous_state); - -static void -hildon_calendar_style_set (GtkWidget *widget, - GtkStyle *previous_style); - -static void -hildon_calendar_paint_header (GtkWidget *widget); - -static void -hildon_calendar_paint_footer (GtkWidget *widget); - -static void -hildon_calendar_paint_day_names (GtkWidget *widget); - -static void -hildon_calendar_paint_week_numbers (GtkWidget *widget); - -static void -hildon_calendar_paint_main (GtkWidget *widget); - -static void -hildon_calendar_select_and_focus_day (HildonCalendar *calendar, - guint day); - -static void -hildon_calendar_paint_arrow (GtkWidget *widget, - guint arrow); - -static void -hildon_calendar_paint_day_num (GtkWidget *widget, - gint day); - -static void -hildon_calendar_paint_day (GtkWidget *widget, - gint row, - gint col); - -static void -hildon_calendar_compute_days (HildonCalendar *calendar); - -static gint -left_x_for_column (HildonCalendar *calendar, - gint column); - -static gint -top_y_for_row (HildonCalendar *calendar, - gint row); - -static void -hildon_calendar_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time); - -static void -hildon_calendar_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time); - -static gboolean -hildon_calendar_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time); - -static void -hildon_calendar_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time); - -static gboolean -hildon_calendar_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time); - -/* This function was added because we need to mark current day according to - * specifications - */ - -static void -hildon_calendar_check_current_date (HildonCalendar *calendar, - gint x, - gint y); - -GType G_GNUC_CONST -hildon_calendar_get_type (void) -{ - static GType calendar_type = 0; - - if (!calendar_type) - { - static const GTypeInfo calendar_info = - { - sizeof (HildonCalendarClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_calendar_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonCalendar), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_calendar_init, - }; - - calendar_type = g_type_register_static (GTK_TYPE_WIDGET, "HildonCalendar", - &calendar_info, 0); - } - - return calendar_type; -} - -static void -locales_init (HildonCalendarPrivate *priv) -{ - /* Hildon: This is not exactly portable, see - * http://bugzilla.gnome.org/show_bug.cgi?id=343415 - * The labels need to be instance variables as the startup wizard changes - * locale on runtime. - */ - locale_t l; - - l = newlocale (LC_TIME_MASK, setlocale (LC_MESSAGES, NULL), NULL); - - priv->abbreviated_dayname[0] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_1, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[1] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_2, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[2] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_3, l), - -1, NULL, NULL, NULL) ; - priv->abbreviated_dayname[3] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_4, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[4] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_5, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[5] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_6, l), - -1, NULL, NULL, NULL); - priv->abbreviated_dayname[6] = g_locale_to_utf8 (nl_langinfo_l(ABDAY_7, l), - -1, NULL, NULL, NULL); - priv->monthname[0] = g_locale_to_utf8 (nl_langinfo_l(MON_1, l), - -1, NULL, NULL, NULL); - priv->monthname[1] = g_locale_to_utf8 (nl_langinfo_l(MON_2, l), - -1, NULL, NULL, NULL); - priv->monthname[2] = g_locale_to_utf8 (nl_langinfo_l(MON_3, l), - -1, NULL, NULL, NULL); - priv->monthname[3] = g_locale_to_utf8 (nl_langinfo_l(MON_4, l), - -1, NULL, NULL, NULL); - priv->monthname[4] = g_locale_to_utf8 (nl_langinfo_l(MON_5, l), - -1, NULL, NULL, NULL); - priv->monthname[5] = g_locale_to_utf8 (nl_langinfo_l(MON_6, l), - -1, NULL, NULL, NULL); - priv->monthname[6] = g_locale_to_utf8 (nl_langinfo_l(MON_7, l), - -1, NULL, NULL, NULL); - priv->monthname[7] = g_locale_to_utf8 (nl_langinfo_l(MON_8, l), - -1, NULL, NULL, NULL); - priv->monthname[8] = g_locale_to_utf8 (nl_langinfo_l(MON_9, l), - -1, NULL, NULL, NULL); - priv->monthname[9] = g_locale_to_utf8 (nl_langinfo_l(MON_10, l), - -1, NULL, NULL, NULL); - priv->monthname[10] = g_locale_to_utf8 (nl_langinfo_l(MON_11, l), - -1, NULL, NULL, NULL); - priv->monthname[11] = g_locale_to_utf8 (nl_langinfo_l(MON_12, l), - -1, NULL, NULL, NULL); - - freelocale (l); -} - -static void -hildon_calendar_class_init (HildonCalendarClass *class) -{ - GObjectClass *gobject_class; - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - gobject_class = (GObjectClass*) class; - object_class = (GtkObjectClass*) class; - widget_class = (GtkWidgetClass*) class; - - parent_class = g_type_class_peek_parent (class); - - gobject_class->set_property = hildon_calendar_set_property; - gobject_class->get_property = hildon_calendar_get_property; - gobject_class->finalize = hildon_calendar_finalize; - - object_class->destroy = hildon_calendar_destroy; - - widget_class->realize = hildon_calendar_realize; - widget_class->unrealize = hildon_calendar_unrealize; - widget_class->expose_event = hildon_calendar_expose; - widget_class->size_request = hildon_calendar_size_request; - widget_class->size_allocate = hildon_calendar_size_allocate; - widget_class->button_press_event = hildon_calendar_button_press; - widget_class->button_release_event = hildon_calendar_button_release; - widget_class->motion_notify_event = hildon_calendar_motion_notify; - widget_class->enter_notify_event = hildon_calendar_enter_notify; - widget_class->leave_notify_event = hildon_calendar_leave_notify; - widget_class->key_press_event = hildon_calendar_key_press; - widget_class->scroll_event = hildon_calendar_scroll; - widget_class->style_set = hildon_calendar_style_set; - widget_class->state_changed = hildon_calendar_state_changed; - widget_class->grab_notify = hildon_calendar_grab_notify; - widget_class->focus_out_event = hildon_calendar_focus_out; - - widget_class->drag_data_get = hildon_calendar_drag_data_get; - widget_class->drag_motion = hildon_calendar_drag_motion; - widget_class->drag_leave = hildon_calendar_drag_leave; - widget_class->drag_drop = hildon_calendar_drag_drop; - widget_class->drag_data_received = hildon_calendar_drag_data_received; - - class->month_changed = NULL; - class->day_selected = NULL; - class->day_selected_double_click = NULL; - class->prev_month = NULL; - class->next_month = NULL; - class->prev_year = NULL; - class->next_year = NULL; - - /** - * HildonCalendar:year: - * - * The selected year. - */ - g_object_class_install_property (gobject_class, - PROP_YEAR, - g_param_spec_int ("year", - "Year", - "The selected year", - 0, G_MAXINT, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:month: - * - * The selected month as number between 0 and 11. - */ - g_object_class_install_property (gobject_class, - PROP_MONTH, - g_param_spec_int ("month", - "Month", - "The selected month (as a number between 0 and 11)", - 0, 11, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:day: - * - * The selected day as number between 1 and 31 or 0 to unselect the currently selected day. - */ - g_object_class_install_property (gobject_class, - PROP_DAY, - g_param_spec_int ("day", - "Day", - "The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day)", - 0, 31, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:show-heading: - * - * Determines whether a heading is displayed. - * - */ - g_object_class_install_property (gobject_class, - PROP_SHOW_HEADING, - g_param_spec_boolean ("show-heading", - "Show Heading", - "If TRUE, a heading is displayed", - TRUE, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:show-day-names: - * - * Determines whether day names are displayed. - * - */ - g_object_class_install_property (gobject_class, - PROP_SHOW_DAY_NAMES, - g_param_spec_boolean ("show-day-names", - "Show Day Names", - "If TRUE, day names are displayed", - TRUE, - GTK_PARAM_READWRITE)); - /** - * HildonCalendar:no-month-change: - * - * Determines whether the selected month can be changed. - * - */ - g_object_class_install_property (gobject_class, - PROP_NO_MONTH_CHANGE, - g_param_spec_boolean ("no-month-change", - "No Month Change", - "If TRUE, the selected month cannot be changed", - FALSE, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:show-week-numbers: - * - * Determines whether week numbers are displayed. - * - */ - g_object_class_install_property (gobject_class, - PROP_SHOW_WEEK_NUMBERS, - g_param_spec_boolean ("show-week-numbers", - "Show Week Numbers", - "If TRUE, week numbers are displayed", - FALSE, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:week-start: - * - * Determines the start day of the week (0 for Sunday, 1 for Monday etc.) - * - */ - g_object_class_install_property (gobject_class, - PROP_WEEK_START, - g_param_spec_int ("week-start", - "Week start day", - "First day of the week; 0 for Sunday, 1 for Monday etc.", - 0, 6, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:min-year: - * - * Minimum valid year (0 if no limit). - * - */ - g_object_class_install_property (gobject_class, - PROP_MIN_YEAR, - g_param_spec_int ("min-year", - "Minimum valid year", - "Minimum valid year (0 if no limit)", - 0, 10000, 0, - GTK_PARAM_READWRITE)); - - /** - * HildonCalendar:max-year: - * - * Maximum valid year (0 if no limit). - * - */ - g_object_class_install_property (gobject_class, - PROP_MAX_YEAR, - g_param_spec_int ("max-year", - "Maximum valid year", - "Maximum valid year (0 if no limit)", - 0, 10000, 0, - GTK_PARAM_READWRITE)); - - hildon_calendar_signals[MONTH_CHANGED_SIGNAL] = - g_signal_new ("month_changed", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, month_changed), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[DAY_SELECTED_SIGNAL] = - g_signal_new ("day_selected", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, day_selected), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL] = - g_signal_new ("day_selected_double_click", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, day_selected_double_click), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[PREV_MONTH_SIGNAL] = - g_signal_new ("prev_month", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, prev_month), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[NEXT_MONTH_SIGNAL] = - g_signal_new ("next_month", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, next_month), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[PREV_YEAR_SIGNAL] = - g_signal_new ("prev_year", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, prev_year), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - hildon_calendar_signals[NEXT_YEAR_SIGNAL] = - g_signal_new ("next_year", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonCalendarClass, next_year), - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - /** - * HildonCalendar::erroneous-date: - * - * Emitted when the user tries to set a date which is outside the boundaries - * set by min-year and max-year properties. - * - */ - hildon_calendar_signals[ERRONEOUS_DATE_SIGNAL] = - g_signal_new ("erroneous_date", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); - /** - * HildonCalendar::selected-date: - * - * Emitted on button-release when the user has selected a date. - * - */ - hildon_calendar_signals[SELECTED_DATE_SIGNAL] = - g_signal_new ("selected_date", - G_OBJECT_CLASS_TYPE(gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - _hildon_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void -hildon_calendar_init (HildonCalendar *calendar) -{ - time_t secs; - struct tm *tm; - gint i; - /* char buffer[255];*/ - /* time_t tmp_time;*/ - GtkWidget *widget; - HildonCalendarPrivate *private_data; - /* gchar *year_before;*/ - /* gint row; - gint col; */ - gchar *langinfo; - GDateWeekday week_1stday; - gint first_weekday; - guint week_origin; - - widget = GTK_WIDGET (calendar); - GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS); - - calendar->private_data = g_malloc (sizeof (HildonCalendarPrivate)); - private_data = HILDON_CALENDAR_GET_PRIVATE (calendar); - - /* Set defaults */ - secs = time (NULL); - tm = localtime (&secs); - calendar->month = tm->tm_mon; - calendar->year = 1900 + tm->tm_year; - - for (i=0;i<31;i++) - calendar->marked_date[i] = FALSE; - calendar->num_marked_dates = 0; - calendar->selected_day = tm->tm_mday; - - calendar->display_flags = ( HILDON_CALENDAR_SHOW_HEADING | - HILDON_CALENDAR_SHOW_DAY_NAMES ); - - /* Hildon: we should mark current day and we need to store current date */ - private_data->current_day = tm->tm_mday; - private_data->current_month = tm->tm_mon; - private_data->current_year = tm->tm_year + 1900; - - /* Hildon: following lines are for stylus sliding */ - private_data->slide_stylus = FALSE; - private_data->prev_row = -1; - private_data->prev_col = -1; - - /* Hildon: is_bad_day indicate if day was selected out of legal range */ - private_data->is_bad_day = FALSE; - - calendar->highlight_row = -1; - calendar->highlight_col = -1; - - calendar->focus_row = -1; - calendar->focus_col = -1; - calendar->xor_gc = NULL; - - private_data->max_year_width = 0; - private_data->max_month_width = 0; - private_data->max_day_char_width = 0; - private_data->max_week_char_width = 0; - - private_data->max_day_char_ascent = 0; - private_data->max_day_char_descent = 0; - private_data->max_label_char_ascent = 0; - private_data->max_label_char_descent = 0; - - /* private_data->arrow_width = 10;*/ - - private_data->freeze_count = 0; - - private_data->dirty_header = 0; - private_data->dirty_day_names = 0; - private_data->dirty_week = 0; - private_data->dirty_main = 0; - - private_data->need_timer = 0; - private_data->timer = 0; - private_data->click_child = -1; - - private_data->in_drag = 0; - private_data->drag_highlight = 0; - - private_data->min_year = 0; - private_data->max_year = 0; - - gtk_drag_dest_set (widget, 0, NULL, 0, GDK_ACTION_COPY); - gtk_drag_dest_add_text_targets (widget); - -#if 0 - private_data->year_before = 0; - - /* Translate to calendar:YM if you want years to be displayed - * before months; otherwise translate to calendar:MY. - * Do *not* translate it to anything else, if it - * it isn't calendar:YM or calendar:MY it will not work. - * - * Note that this flipping is in top the text direction flipping, - * so if you have a default text direction of RTL and YM, then - * the year will appear on the right. - */ - year_before = _("calendar:MY"); - if (strcmp (year_before, "calendar:YM") == 0) - private_data->year_before = 1; - else if (strcmp (year_before, "calendar:MY") != 0) - g_warning ("Whoever translated calendar:MY did so wrongly.\n"); -#endif - langinfo = nl_langinfo (_NL_TIME_FIRST_WEEKDAY); - first_weekday = langinfo[0]; - langinfo = nl_langinfo (_NL_TIME_WEEK_1STDAY); - week_origin = GPOINTER_TO_UINT (langinfo); - if (week_origin == 19971130) - week_1stday = G_DATE_SUNDAY; - else if (week_origin == 19971201) - week_1stday = G_DATE_MONDAY; - else if (g_date_valid_dmy ((week_origin % 100), - (week_origin / 100) % 100, - (week_origin / 10000))) - { - GDate *date; - date = g_date_new_dmy ((week_origin % 100), - (week_origin / 100) % 100, - (week_origin / 10000)); - week_1stday = g_date_get_weekday (date); - g_date_free (date); - } - else - { - g_warning ("Invalid value set for _NL_TIME_WEEK_1STDAY"); - week_1stday = G_DATE_SUNDAY; - } - - private_data->week_start = (week_1stday + first_weekday - 1) % 7; - - locales_init (private_data); -} - -GtkWidget* -hildon_calendar_new (void) -{ - return g_object_new (HILDON_TYPE_CALENDAR, NULL); -} - -/* column_from_x: returns the column 0-6 that the - * x pixel of the xwindow is in */ -static gint -column_from_x (HildonCalendar *calendar, - gint event_x) -{ - gint c, column; - gint x_left, x_right; - - column = -1; - - for (c = 0; c < 7; c++) - { - x_left = left_x_for_column (calendar, c); - x_right = x_left + HILDON_CALENDAR_GET_PRIVATE (calendar)->day_width; - - if (event_x >= x_left && event_x < x_right) - { - column = c; - break; - } - } - - return column; -} -#if 0 - static gint -row_height (HildonCalendar *calendar) -{ - return (HILDON_CALENDAR_GET_PRIVATE (calendar)->main_h - CALENDAR_MARGIN - - ((calendar->display_flags & HILDON_CALENDAR_SHOW_DAY_NAMES) - ? CALENDAR_YSEP : CALENDAR_MARGIN)) / 6; -} -#endif - -/* row_from_y: returns the row 0-5 that the - * y pixel of the xwindow is in */ -static gint -row_from_y (HildonCalendar *calendar, - gint event_y) -{ - gint r, row; - /*gint height;*/ - gint y_top, y_bottom; - - row = -1; - - for (r = 0; r < 6; r++) - { - y_top = top_y_for_row (calendar, r); - y_bottom = y_top + HILDON_DAY_HEIGHT /*height*/; - - if (event_y >= y_top && event_y < y_bottom) - { - row = r; - break; - } - } - - return row; -} - -/* left_x_for_column: returns the x coordinate - * for the left of the column */ -static gint -left_x_for_column (HildonCalendar *calendar, - gint column) -{ - gint width; - gint x_left; - - if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL) - column = 6 - column; - - width = HILDON_CALENDAR_GET_PRIVATE (calendar)->day_width; - if (calendar->display_flags & HILDON_CALENDAR_SHOW_WEEK_NUMBERS) - x_left = CALENDAR_XSEP + (width + DAY_XSEP) * column; - else - x_left = CALENDAR_MARGIN + (width + DAY_XSEP) * column; - - return x_left; -} - -/* top_y_for_row: returns the y coordinate - * for the top of the row */ -static gint -top_y_for_row (HildonCalendar *calendar, - gint row) -{ - return (HILDON_CALENDAR_GET_PRIVATE (calendar)->main_h - - (CALENDAR_MARGIN + (6 - row) - * HILDON_DAY_HEIGHT)); -} - -static void -hildon_calendar_set_month_prev (HildonCalendar *calendar) -{ - HildonCalendarPrivate *priv = HILDON_CALENDAR_GET_PRIVATE (calendar); - gint month_len; - - if (calendar->display_flags & HILDON_CALENDAR_NO_MONTH_CHANGE) - return; - - if (calendar->month == 0) - { - if (!priv->min_year || calendar->year > priv->min_year) - { - calendar->month = 11; - calendar->year--; - } - } - else - calendar->month--; - - month_len = month_length[leap (calendar->year)][calendar->month + 1]; - - hildon_calendar_freeze (calendar); - hildon_calendar_compute_days (calendar); - - g_signal_emit (calendar, - hildon_calendar_signals[PREV_MONTH_SIGNAL], - 0); - g_signal_emit (calendar, - hildon_calendar_signals[MONTH_CHANGED_SIGNAL], - 0); - - if (month_len < calendar->selected_day) - { - calendar->selected_day = 0; - hildon_calendar_select_day (calendar, month_len); - } - else - { - if (calendar->selected_day < 0) - calendar->selected_day = calendar->selected_day + 1 + month_length[leap (calendar->year)][calendar->month + 1]; - hildon_calendar_select_day (calendar, calendar->selected_day); - } - - gtk_widget_queue_draw (GTK_WIDGET (calendar)); - hildon_calendar_thaw (calendar); -} - -static void -hildon_calendar_set_month_next (HildonCalendar *calendar) -{ - HildonCalendarPrivate *priv; - gint month_len; - - g_return_if_fail (GTK_IS_WIDGET (calendar)); - - priv = HILDON_CALENDAR_GET_PRIVATE (calendar); - - if (calendar->display_flags & HILDON_CALENDAR_NO_MONTH_CHANGE) - return; - - if (calendar->month == 11) - { - if (!priv->max_year || calendar->year < priv->max_year) - { - calendar->month = 0; - calendar->year++; - } - } - else - calendar->month++; - - hildon_calendar_freeze (calendar); - hildon_calendar_compute_days (calendar); - g_signal_emit (calendar, - hildon_calendar_signals[NEXT_MONTH_SIGNAL], - 0); - g_signal_emit (calendar, - hildon_calendar_signals[MONTH_CHANGED_SIGNAL], - 0); - - month_len = month_length[leap (calendar->year)][calendar->month + 1]; - - if (month_len < calendar->selected_day) - { - calendar->selected_day = 0; - hildon_calendar_select_day (calendar, month_len); - } - else - hildon_calendar_select_day (calendar, calendar->selected_day); - - gtk_widget_queue_draw (GTK_WIDGET (calendar)); - hildon_calendar_thaw (calendar); -} - -static void -hildon_calendar_set_year_prev (HildonCalendar *calendar) -{ - HildonCalendarPrivate *priv; - gint month_len; - - g_return_if_fail (GTK_IS_WIDGET (calendar)); - - priv = HILDON_CALENDAR_GET_PRIVATE (calendar); - - if (!priv->min_year || priv->min_year < calendar->year) - calendar->year--; - - hildon_calendar_freeze (calendar); - hildon_calendar_compute_days (calendar); - g_signal_emit (calendar, - hildon_calendar_signals[PREV_YEAR_SIGNAL], - 0); - g_signal_emit (calendar, - hildon_calendar_signals[MONTH_CHANGED_SIGNAL], - 0); - - month_len = month_length[leap (calendar->year)][calendar->month + 1]; - - if (month_len < calendar->selected_day) - { - calendar->selected_day = 0; - hildon_calendar_select_day (calendar, month_len); - } - else - hildon_calendar_select_day (calendar, calendar->selected_day); - - gtk_widget_queue_draw (GTK_WIDGET (calendar)); - hildon_calendar_thaw (calendar); -} - -static void -hildon_calendar_set_year_next (HildonCalendar *calendar) -{ - HildonCalendarPrivate *priv; - gint month_len; - - g_return_if_fail (GTK_IS_WIDGET (calendar)); - priv = HILDON_CALENDAR_GET_PRIVATE (calendar); - - hildon_calendar_freeze (calendar); - - if (!priv->max_year || priv->max_year > calendar->year) - calendar->year++; - - hildon_calendar_compute_days (calendar); - g_signal_emit (calendar, - hildon_calendar_signals[NEXT_YEAR_SIGNAL], - 0); - g_signal_emit (calendar, - hildon_calendar_signals[MONTH_CHANGED_SIGNAL], - 0); - - month_len = month_length[leap (calendar->year)][calendar->month + 1]; - - if (month_len < calendar->selected_day) - { - calendar->selected_day = 0; - hildon_calendar_select_day (calendar, month_len); - } - else - hildon_calendar_select_day (calendar, calendar->selected_day); - gtk_widget_queue_draw (GTK_WIDGET (calendar)); - hildon_calendar_thaw (calendar); -} - -static void -hildon_calendar_main_button (GtkWidget *widget, - GdkEventButton *event) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - gint x, y; - gint row, col; - gint day_month; - gint day; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - x = (gint) (event->x); - y = (gint) (event->y); - - row = row_from_y (calendar, y); - col = column_from_x (calendar, x); - - /* If row or column isn't found, just return. */ - if (row == -1 || col == -1) - return; - - day_month = calendar->day_month[row][col]; - - if ((calendar->year == private_data->min_year && - calendar->month == 0 && day_month == MONTH_PREV) || - (calendar->year == private_data->max_year && - calendar->month == 11 && day_month == MONTH_NEXT)) - { - private_data->is_bad_day = TRUE; - g_signal_emit (calendar, hildon_calendar_signals[ERRONEOUS_DATE_SIGNAL], 0); - return; - } - - if (event->type == GDK_BUTTON_RELEASE) - { - day = calendar->day[row][col]; - - if (day_month == MONTH_PREV) - { - hildon_calendar_set_month_prev (calendar); - } - else if (day_month == MONTH_NEXT) - { - hildon_calendar_set_month_next (calendar); - } - - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - - if (event->button == 1) - { - private_data->in_drag = 1; - private_data->drag_start_x = x; - private_data->drag_start_y = y; - } - - hildon_calendar_select_and_focus_day (calendar, day); - } - else if (event->type == GDK_2BUTTON_PRESS) - { - private_data->in_drag = 0; - private_data->slide_stylus = FALSE; - if (day_month == MONTH_CURRENT) - g_signal_emit (calendar, - hildon_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL], 0); - } -} - -static void -hildon_calendar_realize_arrows (GtkWidget *widget) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - GdkWindowAttr attributes; - gint attributes_mask; - gint i; - guint arrow_vlength, arrow_hlength; - /*gboolean year_left;*/ - - g_return_if_fail (HILDON_IS_CALENDAR (widget)); - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - gtk_widget_style_get (widget, - "scroll-arrow-hlength", &arrow_hlength, - "scroll-arrow-vlength", &arrow_vlength, - NULL); - /* - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) - year_left = private_data->year_before; - else - year_left = !private_data->year_before; - */ - /* Arrow windows ------------------------------------- */ - if (! (calendar->display_flags & HILDON_CALENDAR_NO_MONTH_CHANGE) - && (calendar->display_flags & HILDON_CALENDAR_SHOW_HEADING)) - { - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.window_type = GDK_WINDOW_CHILD; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK); - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - attributes.y = 0; - attributes.width = arrow_vlength; - attributes.height = arrow_hlength; - - attributes.x = (widget->allocation.width - private_data->max_year_width) / 2 - arrow_vlength - HILDON_ARROW_SEP; - private_data->arrow_win[ARROW_YEAR_LEFT] = gdk_window_new (private_data->header_win, - &attributes, attributes_mask); - - attributes.x = (widget->allocation.width + private_data->max_year_width) / 2 + HILDON_ARROW_SEP; - private_data->arrow_win[ARROW_YEAR_RIGHT] = gdk_window_new (private_data->header_win, - &attributes, attributes_mask); - attributes.x = (widget->allocation.width - private_data->max_month_width) / 2 - arrow_vlength - HILDON_ARROW_SEP; - private_data->arrow_win[ARROW_MONTH_LEFT] = gdk_window_new (private_data->footer_win, - &attributes, attributes_mask); - attributes.x = (widget->allocation.width + private_data->max_month_width) / 2 + HILDON_ARROW_SEP; - private_data->arrow_win[ARROW_MONTH_RIGHT] = gdk_window_new (private_data->footer_win, - &attributes, attributes_mask); - - /* - for (i = 0; i < 4; i++) - { - switch (i) - { - case ARROW_MONTH_LEFT: - if (year_left) - attributes.x = (widget->allocation.width - 2 * widget->style->xthickness - - (3 + 2*private_data->arrow_width - + private_data->max_month_width)); - else - attributes.x = 3; - break; - case ARROW_MONTH_RIGHT: - if (year_left) - attributes.x = (widget->allocation.width - 2 * widget->style->xthickness - - 3 - private_data->arrow_width); - else - attributes.x = (private_data->arrow_width - + private_data->max_month_width); - break; - case ARROW_YEAR_LEFT: - if (year_left) - attributes.x = 3; - else - attributes.x = (widget->allocation.width - 2 * widget->style->xthickness - - (3 + 2*private_data->arrow_width - + private_data->max_year_width)); - break; - case ARROW_YEAR_RIGHT: - if (year_left) - attributes.x = (private_data->arrow_width - + private_data->max_year_width); - else - attributes.x = (widget->allocation.width - 2 * widget->style->xthickness - - 3 - private_data->arrow_width); - break; - } - private_data->arrow_win[i] = gdk_window_new (private_data->header_win, - &attributes, - attributes_mask);*/ - - for (i = 0; i < 4; i++) - { - if (GTK_WIDGET_IS_SENSITIVE (widget)) - private_data->arrow_state[i] = GTK_STATE_NORMAL; - else - private_data->arrow_state[i] = GTK_STATE_INSENSITIVE; - gdk_window_set_background (private_data->arrow_win[i], - HEADER_BG_COLOR (GTK_WIDGET (calendar))); - gdk_window_show (private_data->arrow_win[i]); - gdk_window_set_user_data (private_data->arrow_win[i], widget); - } - } - else - { - for (i = 0; i < 4; i++) - private_data->arrow_win[i] = NULL; - } -} - -static void -hildon_calendar_realize_header (GtkWidget *widget) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - GdkWindowAttr attributes; - gint attributes_mask; - guint arrow_hlength; - - g_return_if_fail (HILDON_IS_CALENDAR (widget)); - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - gtk_widget_style_get (widget, - "scroll-arrow-hlength", &arrow_hlength, - NULL); - /* Header window ------------------------------------- */ - if (calendar->display_flags & HILDON_CALENDAR_SHOW_HEADING) - { - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.window_type = GDK_WINDOW_CHILD; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - attributes.x = 0 /*widget->style->xthickness*/; - attributes.y = 0 /*widget->style->ythickness*/; - attributes.width = widget->allocation.width; /* - 2 * attributes.x */; - attributes.height = arrow_hlength /*private_data->header_h - 2 * attributes.y*/; - private_data->header_win = gdk_window_new (widget->window, - &attributes, attributes_mask); - - attributes.y = arrow_hlength + 2 * CALENDAR_YSEP + private_data->main_h + private_data->day_name_h; - - private_data->footer_win = gdk_window_new(widget->window, - &attributes, attributes_mask); - - gdk_window_set_background (private_data->header_win, - HEADER_BG_COLOR (widget)); - gdk_window_set_background (private_data->footer_win, - HEADER_BG_COLOR (widget)); - - gdk_window_show (private_data->header_win); - gdk_window_show (private_data->footer_win); - gdk_window_set_user_data (private_data->header_win, widget); - gdk_window_set_user_data (private_data->footer_win, widget); - } - else - { - private_data->header_win = NULL; - private_data->footer_win = NULL; - } - hildon_calendar_realize_arrows (widget); -} - -static void -hildon_calendar_realize_day_names (GtkWidget *widget) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - GdkWindowAttr attributes; - gint attributes_mask; - - g_return_if_fail (HILDON_IS_CALENDAR (widget)); - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - /* Day names window --------------------------------- */ - if ( calendar->display_flags & HILDON_CALENDAR_SHOW_DAY_NAMES) - { - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.window_type = GDK_WINDOW_CHILD; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - attributes.x = HILDON_DAY_WIDTH + HILDON_WEEKS_EXTRA_WIDTH/*(widget->style->xthickness + INNER_BORDER)*/; - attributes.y = private_data->header_h; - attributes.width = widget->allocation.width - attributes.x; - attributes.height = private_data->day_name_h; - private_data->day_name_win = gdk_window_new (widget->window, - &attributes, - attributes_mask); - gdk_window_set_background (private_data->day_name_win, - BACKGROUND_COLOR ( GTK_WIDGET (calendar))); - - gdk_window_show (private_data->day_name_win); - gdk_window_set_user_data (private_data->day_name_win, widget); - } - else - { - private_data->day_name_win = NULL; - } -} - -static void -hildon_calendar_realize_week_numbers (GtkWidget *widget) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - GdkWindowAttr attributes; - gint attributes_mask; - - g_return_if_fail (HILDON_IS_CALENDAR (widget)); - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - /* Week number window -------------------------------- */ - if (calendar->display_flags & HILDON_CALENDAR_SHOW_WEEK_NUMBERS) - { - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.window_type = GDK_WINDOW_CHILD; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - attributes.x = 0 /*widget->style->xthickness + INNER_BORDER*/; - attributes.y = private_data->header_h; - /*+ (widget->style->ythickness + INNER_BORDER))*/; - attributes.width = HILDON_DAY_WIDTH + HILDON_WEEKS_EXTRA_WIDTH; - attributes.height = private_data->main_h + private_data->day_name_h; - private_data->week_win = gdk_window_new (widget->window, - &attributes, attributes_mask); - gdk_window_set_background (private_data->week_win, - BACKGROUND_COLOR (GTK_WIDGET (calendar))); - gdk_window_show (private_data->week_win); - gdk_window_set_user_data (private_data->week_win, widget); - } - else - { - private_data->week_win = NULL; - } -} - -static void -hildon_calendar_realize (GtkWidget *widget) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - GdkWindowAttr attributes; - gint attributes_mask; - GdkGCValues values; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - hildon_calendar_compute_days (calendar); - - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.window_type = GDK_WINDOW_CHILD; - attributes.event_mask = (gtk_widget_get_events (widget) - | GDK_EXPOSURE_MASK |GDK_KEY_PRESS_MASK | GDK_SCROLL_MASK); - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - widget->window = gdk_window_new (widget->parent->window, - &attributes, attributes_mask); - - widget->style = gtk_style_attach (widget->style, widget->window); - - /* Header window ------------------------------------- */ - hildon_calendar_realize_header (widget); - /* Day names window --------------------------------- */ - hildon_calendar_realize_day_names (widget); - /* Week number window -------------------------------- */ - hildon_calendar_realize_week_numbers (widget); - /* Main Window -------------------------------------- */ - attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK - | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - | GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK); - - attributes.x = HILDON_DAY_WIDTH + HILDON_WEEKS_EXTRA_WIDTH /*private_data->week_width + (widget->style->ythickness + INNER_BORDER)*/; - attributes.y = (private_data->header_h + private_data->day_name_h - + (widget->style->ythickness + INNER_BORDER)); - attributes.width = (widget->allocation.width - attributes.x - /*- (widget->style->xthickness + INNER_BORDER)*/); - attributes.height = private_data->main_h; - private_data->main_win = gdk_window_new (widget->window, - &attributes, attributes_mask); - gdk_window_set_background (private_data->main_win, - BACKGROUND_COLOR ( GTK_WIDGET ( calendar))); - gdk_window_show (private_data->main_win); - gdk_window_set_user_data (private_data->main_win, widget); - gdk_window_set_background (widget->window, BACKGROUND_COLOR (widget)); - gdk_window_show (widget->window); - gdk_window_set_user_data (widget->window, widget); - - /* Set widgets gc */ - calendar->gc = gdk_gc_new (widget->window); - - values.foreground = widget->style->white; - values.function = GDK_XOR; - calendar->xor_gc = gdk_gc_new_with_values (widget->window, - &values, - GDK_GC_FOREGROUND | - GDK_GC_FUNCTION); -} - -static void -hildon_calendar_unrealize (GtkWidget *widget) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - gint i; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (private_data->header_win) - { - for (i = 0; i < 4; i++) - { - if (private_data->arrow_win[i]) - { - gdk_window_set_user_data (private_data->arrow_win[i], NULL); - gdk_window_destroy (private_data->arrow_win[i]); - private_data->arrow_win[i] = NULL; - } - } - gdk_window_set_user_data (private_data->header_win, NULL); - gdk_window_destroy (private_data->header_win); - private_data->header_win = NULL; - gdk_window_set_user_data (private_data->footer_win, NULL); - gdk_window_destroy (private_data->footer_win); - private_data->footer_win = NULL; - } - - if (private_data->week_win) - { - gdk_window_set_user_data (private_data->week_win, NULL); - gdk_window_destroy (private_data->week_win); - private_data->week_win = NULL; - } - - if (private_data->main_win) - { - gdk_window_set_user_data (private_data->main_win, NULL); - gdk_window_destroy (private_data->main_win); - private_data->main_win = NULL; - } - if (private_data->day_name_win) - { - gdk_window_set_user_data (private_data->day_name_win, NULL); - gdk_window_destroy (private_data->day_name_win); - private_data->day_name_win = NULL; - } - if (calendar->xor_gc) - g_object_unref (calendar->xor_gc); - if (calendar->gc) - g_object_unref (calendar->gc); - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); -} - -static void -hildon_calendar_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - PangoLayout *layout; - PangoRectangle logical_rect; - - /*gint height;*/ - gint i; - gchar buffer[255]; - /*gint calendar_margin = CALENDAR_MARGIN;*/ - gint header_width, main_width; - gint max_header_height = 0; - gint focus_width; - gint focus_padding; - gint arrow_hlength; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - gtk_widget_style_get (GTK_WIDGET (widget), - "focus-line-width", &focus_width, - "focus-padding", &focus_padding, - "scroll-arrow-hlength", &arrow_hlength, - NULL); - - layout = gtk_widget_create_pango_layout (widget, NULL); - - /* - * Calculate the requisition width for the widget. - */ - - /* Header width */ - - if (calendar->display_flags & HILDON_CALENDAR_SHOW_HEADING) - { - private_data->max_month_width = 0; - for (i = 0; i < 12; i++) - { - pango_layout_set_text (layout, private_data->monthname[i], -1); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - private_data->max_month_width = MAX (private_data->max_month_width, - logical_rect.width + 8); - max_header_height = MAX (max_header_height, logical_rect.height); - } - private_data->max_year_width = 0; - for (i=0; i<10; i++) - { - g_snprintf (buffer, sizeof (buffer), "%d%d%d%d", i,i,i,i); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - private_data->max_year_width = MAX (private_data->max_year_width, - logical_rect.width + 8); - max_header_height = MAX (max_header_height, logical_rect.height); - } - } - else - { - private_data->max_month_width = 0; - private_data->max_year_width = 0; - } - - if (calendar->display_flags & HILDON_CALENDAR_NO_MONTH_CHANGE) - header_width = (private_data->max_month_width - + private_data->max_year_width - + 3 * 3); - else - header_width = (private_data->max_month_width - + private_data->max_year_width - + 4 * private_data->arrow_width + 3 * 3); - - /* Mainwindow labels width */ - - private_data->max_day_char_width = 0; - private_data->min_day_width = 0; - private_data->max_label_char_ascent = 0; - private_data->max_label_char_descent = 0; - - for (i = 0; i < 9; i++) - { - g_snprintf (buffer, sizeof (buffer), "%d%d", i, i); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - private_data->min_day_width = MAX (private_data->min_day_width, - logical_rect.width); - - private_data->max_day_char_ascent = MAX (private_data->max_label_char_ascent, - PANGO_ASCENT (logical_rect)); - private_data->max_day_char_descent = MAX (private_data->max_label_char_descent, - PANGO_DESCENT (logical_rect)); - } - /* We add one to max_day_char_width to be able to make the marked day "bold" */ - private_data->max_day_char_width = private_data->min_day_width / 2 + 1; - - if (calendar->display_flags & HILDON_CALENDAR_SHOW_DAY_NAMES) - for (i = 0; i < 7; i++) - { - pango_layout_set_text (layout, private_data->abbreviated_dayname[i], -1); - pango_layout_line_get_pixel_extents (pango_layout_get_lines (layout)->data, NULL, &logical_rect); - - /* Hildon: add 4 so that passive focus wouldn't overlap day names */ - private_data->min_day_width = MAX (private_data->min_day_width, logical_rect.width + 4); - private_data->max_label_char_ascent = MAX (private_data->max_label_char_ascent, - PANGO_ASCENT (logical_rect)); - private_data->max_label_char_descent = MAX (private_data->max_label_char_descent, - PANGO_DESCENT (logical_rect)); - } - - private_data->max_week_char_width = 0; - if (calendar->display_flags & HILDON_CALENDAR_SHOW_WEEK_NUMBERS) - for (i = 0; i < 9; i++) - { - g_snprintf (buffer, sizeof (buffer), "%d%d", i, i); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - private_data->max_week_char_width = MAX (private_data->max_week_char_width, - logical_rect.width / 2); - } - - main_width = (7 * (private_data->min_day_width + (focus_padding + focus_width) * 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2 - + (private_data->max_week_char_width - ? private_data->max_week_char_width * 2 + (focus_padding + focus_width) * 2 + CALENDAR_XSEP * 2 - : 0)); - - /* requisition->width = MAX (header_width, main_width + INNER_BORDER * 2) + widget->style->xthickness * 2; - * - * FIXME: header_width is broken, when Calendar is themed ! - * Next line is workaround for this bug - */ - requisition->width = (main_width + INNER_BORDER * 2) + widget->style->xthickness * 2 + HILDON_WEEKS_EXTRA_WIDTH + HILDON_DAYS_EXTRA_WIDTH; - - /* - * Calculate the requisition height for the widget. - * This is Hildon calculation - */ - - if (calendar->display_flags & HILDON_CALENDAR_SHOW_HEADING) - private_data->header_h = arrow_hlength + CALENDAR_YSEP; - else - private_data->header_h = 0; - - if (calendar->display_flags & HILDON_CALENDAR_SHOW_DAY_NAMES) - private_data->day_name_h = HILDON_DAY_HEIGHT; - else - private_data->day_name_h = 0; - - private_data->main_h = 6 * HILDON_DAY_HEIGHT; - requisition->height = 2 * private_data->header_h + private_data->day_name_h + private_data->main_h; - - g_object_unref (layout); -} - -static void -hildon_calendar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - gint xthickness = widget->style->xthickness; - /*gint ythickness = widget->style->xthickness;*/ - gboolean year_left; - gint arrow_vlength, arrow_hlength; - - widget->allocation = *allocation; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) - year_left = private_data->year_before; - else - year_left = !private_data->year_before; - - gtk_widget_style_get (widget, - "scroll-arrow-vlength", &arrow_vlength, - "scroll-arrow-hlength", &arrow_hlength, - NULL); - - if (calendar->display_flags & HILDON_CALENDAR_SHOW_WEEK_NUMBERS) - { - /* this variable is introduced to avoid breaking week_width because - of HILDON_WEEKS_EXTRA_WIDTH and HILDON_DAYS_EXTRA_WIDTH appearing - in calculation of day_width */ - int real_day_width = (private_data->min_day_width - * ((allocation->width - - (xthickness + INNER_BORDER) * 2 - - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - CALENDAR_XSEP * 2)) - / (7 * private_data->min_day_width + private_data->max_week_char_width * 2)); - - private_data->day_width = (private_data->min_day_width - * ((allocation->width - - (HILDON_WEEKS_EXTRA_WIDTH + HILDON_DAYS_EXTRA_WIDTH) - - (xthickness + INNER_BORDER) * 2 - - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - CALENDAR_XSEP * 2)) - / (7 * private_data->min_day_width + private_data->max_week_char_width * 2)); - private_data->week_width = ((allocation->width - (xthickness + INNER_BORDER) * 2 - - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - CALENDAR_XSEP * 2 ) - - real_day_width * 7 + CALENDAR_MARGIN + CALENDAR_XSEP); - } - else - { - private_data->day_width = (allocation->width - - (xthickness + INNER_BORDER) * 2 - - (CALENDAR_MARGIN * 2) - - (DAY_XSEP * 6))/7; - private_data->week_width = 0; - } - - if (GTK_WIDGET_REALIZED (widget)) - { - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, allocation->height); - if (private_data->header_win) - gdk_window_move_resize (private_data->header_win, - 0, 0, widget->allocation.width, arrow_hlength); - if (private_data->arrow_win[ARROW_YEAR_LEFT]) - { - /* if (year_left) - gdk_window_move_resize (private_data->arrow_win[ARROW_YEAR_LEFT], - 3, 3, - private_data->arrow_width, - private_data->header_h - 7); - else - gdk_window_move_resize (private_data->arrow_win[ARROW_YEAR_LEFT], - (allocation->width - 2 * xthickness - - (3 + 2*private_data->arrow_width - + private_data->max_year_width)), - 3, - private_data->arrow_width, - private_data->header_h - 7);*/ - - gdk_window_move (private_data->arrow_win[ARROW_YEAR_LEFT], - (widget->allocation.width - private_data->max_year_width) / 2 - arrow_vlength - HILDON_ARROW_SEP, 0); - } - if (private_data->arrow_win[ARROW_YEAR_RIGHT]) - { - /* if (year_left) - gdk_window_move_resize (private_data->arrow_win[ARROW_YEAR_RIGHT], - (private_data->arrow_width - + private_data->max_year_width), - 3, - private_data->arrow_width, - private_data->header_h - 7); - else - gdk_window_move_resize (private_data->arrow_win[ARROW_YEAR_RIGHT], - (allocation->width - 2 * xthickness - - 3 - private_data->arrow_width), - 3, - private_data->arrow_width, - private_data->header_h - 7);*/ - gdk_window_move (private_data->arrow_win[ARROW_YEAR_RIGHT], - (widget->allocation.width + private_data->max_year_width) / 2 + HILDON_ARROW_SEP, 0); - } - if (private_data->footer_win) - gdk_window_move_resize (private_data->footer_win, - 0, private_data->header_h + private_data->day_name_h + private_data->main_h + CALENDAR_YSEP, - widget->allocation.width, arrow_hlength); - - if (private_data->arrow_win[ARROW_MONTH_LEFT]) - { - /* if (year_left) - gdk_window_move_resize (private_data->arrow_win[ARROW_MONTH_LEFT], - (allocation->width - 2 * xthickness - - (3 + 2*private_data->arrow_width - + private_data->max_month_width)), - 3, - private_data->arrow_width, - private_data->header_h - 7); - else - gdk_window_move_resize (private_data->arrow_win[ARROW_MONTH_LEFT], - 3, 3, - private_data->arrow_width, - private_data->header_h - 7); - */ - - gdk_window_move (private_data->arrow_win[ARROW_MONTH_LEFT], - (widget->allocation.width - private_data->max_month_width) / 2 - arrow_vlength - HILDON_ARROW_SEP, 0); - } - if (private_data->arrow_win[ARROW_MONTH_RIGHT]) - { - /* if (year_left) - gdk_window_move_resize (private_data->arrow_win[ARROW_MONTH_RIGHT], - (allocation->width - 2 * xthickness - - 3 - private_data->arrow_width), - 3, - private_data->arrow_width, - private_data->header_h - 7); - else - gdk_window_move_resize (private_data->arrow_win[ARROW_MONTH_RIGHT], - (private_data->arrow_width - + private_data->max_month_width), - 3, - private_data->arrow_width, - private_data->header_h - 7);*/ - gdk_window_move (private_data->arrow_win[ARROW_MONTH_RIGHT], - (widget->allocation.width + private_data->max_month_width) / 2 + HILDON_ARROW_SEP, 0); - } - - - if (private_data->day_name_win) - gdk_window_move_resize (private_data->day_name_win, - private_data->week_width, /*xthickness + INNER_BORDER*/ - private_data->header_h /*+ (widget->style->ythickness + INNER_BORDER)*/, - widget->allocation.width - private_data->week_width /*- (xthickness + INNER_BORDER) * 2*/, - private_data->day_name_h); - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) - { - if (private_data->week_win) - gdk_window_move_resize (private_data->week_win, - 0 /*(xthickness + INNER_BORDER)*/, - private_data->header_h /*+ (widget->style->ythickness + INNER_BORDER)*/, - HILDON_DAY_WIDTH, - private_data->main_h + private_data->day_name_h); - gdk_window_move_resize (private_data->main_win, - private_data->week_width /* + (xthickness + INNER_BORDER)*/, - private_data->header_h + private_data->day_name_h - /*+ (widget->style->ythickness + INNER_BORDER)*/, - widget->allocation.width - private_data->week_width - /*- (xthickness + INNER_BORDER) * 2*/, - private_data->main_h); - } - else - { - gdk_window_move_resize (private_data->main_win, - 0 /*(xthickness + INNER_BORDER)*/, - private_data->header_h + private_data->day_name_h - /*+ (widget->style->ythickness + INNER_BORDER)*/, - widget->allocation.width - - private_data->week_width - /*- (xthickness + INNER_BORDER) * 2*/, - private_data->main_h); - if (private_data->week_win) - gdk_window_move_resize (private_data->week_win, - widget->allocation.width - - private_data->week_width - /*- (xthickness + INNER_BORDER)*/, - private_data->header_h + private_data->day_name_h - /*+ (widget->style->ythickness + INNER_BORDER)*/, - private_data->week_width, - private_data->main_h); - } - } -} - -static gboolean -hildon_calendar_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - HildonCalendarPrivate *private_data; - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (GTK_WIDGET_DRAWABLE (widget)) - { - if (event->window == private_data->main_win) - hildon_calendar_paint_main (widget); - - if (event->window == private_data->header_win) - hildon_calendar_paint_header (widget); - if (event->window == private_data->footer_win) - hildon_calendar_paint_footer(widget); - - if (event->window == private_data->day_name_win) - hildon_calendar_paint_day_names (widget); - - if (event->window == private_data->week_win) - hildon_calendar_paint_week_numbers (widget); - } - - /* FIXME This appeared after 2.6 -> 2.10 migration. Without this the - * arrows disappear when spinning through the calendar. Apparently, something - * overdraws them somehow or the expose events go into blackhole. This is - * a dirty fix... but kinda works */ - - hildon_calendar_paint_header (widget); - hildon_calendar_paint_footer (widget); - - return FALSE; -} - -static void -hildon_calendar_paint_header (GtkWidget *widget) -{ - HildonCalendar *calendar; - GdkGC *gc; - char buffer[255]; - int x, y; - gint header_width, cal_height; - HildonCalendarPrivate *private_data; - PangoLayout *layout; - PangoRectangle logical_rect; - gint arrow_hlength; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (private_data->freeze_count) - { - private_data->dirty_header = 1; - return; - } - - private_data->dirty_header = 0; - gc = calendar->gc; - - /* Clear window */ - gdk_window_clear (private_data->header_win); - - header_width = widget->allocation.width /*- 2 * widget->style->xthickness*/; - cal_height = widget->allocation.height; - - g_snprintf (buffer, sizeof (buffer), "%d", calendar->year); - layout = gtk_widget_create_pango_layout (widget, buffer); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - gtk_widget_style_get (widget, "scroll-arrow-hlength", &arrow_hlength, NULL); - - y = (arrow_hlength - logical_rect.height) / 2; - x = (widget->allocation.width - logical_rect.width) / 2; - - /* Draw year and its arrows */ - gdk_gc_set_foreground (gc, HEADER_FG_COLOR (GTK_WIDGET (calendar))); - gdk_draw_layout (private_data->header_win, gc, x, y, layout); - - hildon_calendar_paint_arrow (widget, ARROW_YEAR_LEFT); - hildon_calendar_paint_arrow (widget, ARROW_YEAR_RIGHT); - - g_object_unref (layout); -} - -static void -hildon_calendar_paint_footer (GtkWidget *widget) -{ - HildonCalendar *calendar; - GdkGC *gc; - char buffer[255]; - int x, y; - gint header_width, cal_height; - HildonCalendarPrivate *private_data; - PangoLayout *layout; - PangoRectangle logical_rect; - gint arrow_hlength; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (private_data->freeze_count) - { - private_data->dirty_header = 1; - return; - } - - private_data->dirty_header = 0; - gc = calendar->gc; - - /* Clear window */ - gdk_window_clear (private_data->footer_win); - - header_width = widget->allocation.width - 2 * widget->style->xthickness; - cal_height = widget->allocation.height; - - /* Draw month and its arrows */ - g_snprintf (buffer, sizeof (buffer), "%s", private_data->monthname[calendar->month]); - layout = gtk_widget_create_pango_layout (widget, buffer); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - gtk_widget_style_get (widget, "scroll-arrow-hlength", &arrow_hlength, NULL); - - x = (widget->allocation.width - logical_rect.width) / 2; - y = (arrow_hlength - logical_rect.height) / 2; - - gdk_gc_set_foreground (gc, HEADER_FG_COLOR(GTK_WIDGET (calendar))); - gdk_draw_layout (private_data->footer_win, gc, x, y, layout); - - hildon_calendar_paint_arrow (widget, ARROW_MONTH_LEFT); - hildon_calendar_paint_arrow (widget, ARROW_MONTH_RIGHT); - - g_object_unref(layout); -} - -static void -hildon_calendar_paint_day_names (GtkWidget *widget) -{ - HildonCalendar *calendar; - GdkGC *gc; - char buffer[255]; - int day,i; - int day_width, cal_width; - gint cal_height; - int day_wid_sep; - PangoLayout *layout; - PangoRectangle logical_rect; - HildonCalendarPrivate *private_data; - gint focus_padding; - gint focus_width; - - g_return_if_fail (HILDON_IS_CALENDAR (widget)); - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - gc = calendar->gc; - - gtk_widget_style_get (GTK_WIDGET (widget), - "focus-line-width", &focus_width, - "focus-padding", &focus_padding, - NULL); - /* - * Handle freeze/thaw functionality - */ - - if (private_data->freeze_count) - { - private_data->dirty_day_names = 1; - return; - } - private_data->dirty_day_names = 0; - - /* - * Clear the window - */ - - gdk_window_clear (private_data->day_name_win); - - day_width = private_data->day_width; - cal_width = widget->allocation.width; - cal_height = widget->allocation.height; - day_wid_sep = day_width + DAY_XSEP; - - /* - * Draw rectangles as inverted background for the labels. - */ - - /* - * Write the labels - */ - - layout = gtk_widget_create_pango_layout (widget, NULL); - - gdk_gc_set_foreground (gc, SELECTED_FG_COLOR (widget)); - for (i = 0; i < 7; i++) - { - guint x = left_x_for_column (calendar, i); - - if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL) - day = 6 - i; - else - day = i; - day = (day + private_data->week_start) % 7; - g_snprintf (buffer, sizeof (buffer), "%s", private_data->abbreviated_dayname[day]); - - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - /* Hildon: draw passive focus for day name */ - if (calendar->focus_col == i) - gtk_paint_box(GTK_WIDGET (calendar)->style, - private_data->day_name_win, - GTK_STATE_NORMAL, - GTK_SHADOW_OUT, NULL, - GTK_WIDGET (calendar), "passive-focus", - x, - 0, - logical_rect.width + 4, - HILDON_DAY_HEIGHT); - - gdk_draw_layout (private_data->day_name_win, gc, - x + 2, - CALENDAR_MARGIN + focus_width + focus_padding + logical_rect.y, - layout); - } - g_object_unref (layout); -} - -static void -hildon_calendar_paint_week_numbers (GtkWidget *widget) -{ - HildonCalendar *calendar; - GdkGC *gc; - guint row, week = 0, year; - gint x_loc; - char buffer[10]; - gint y_loc; - HildonCalendarPrivate *private_data; - PangoLayout *layout; - PangoRectangle logical_rect; - gint focus_padding; - gint focus_width; - - g_return_if_fail (HILDON_IS_CALENDAR (widget)); - g_return_if_fail (widget->window != NULL); - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - gc = calendar->gc; - - /* - * Handle freeze/thaw functionality - */ - - if (private_data->freeze_count) - { - private_data->dirty_week = 1; - return; - } - private_data->dirty_week = 0; - - gtk_widget_style_get (GTK_WIDGET (widget), - "focus-line-width", &focus_width, - "focus-padding", &focus_padding, - NULL); - - /* - * Clear the window - */ - - gdk_window_clear (private_data->week_win); - - /* - * Draw a rectangle as inverted background for the labels. - */ - - gdk_gc_set_foreground (gc, SELECTED_BG_COLOR (widget)); - - /* Hildon: don't paint background for weekday window */ - - /* - * Write the labels - */ - - layout = gtk_widget_create_pango_layout (widget, NULL); - - gdk_gc_set_foreground (gc, SELECTED_FG_COLOR (widget)); - gdk_draw_line(private_data->week_win, gc, - HILDON_DAY_WIDTH + 7, - 0, - HILDON_DAY_WIDTH + 7, - private_data->main_h + private_data->day_name_h); - - for (row = 0; row < 6; row++) - { - year = calendar->year; - if (calendar->day[row][6] < 15 && row > 3 && calendar->month == 11) - year++; - - g_return_if_fail (week_of_year (&week, &year, - ((calendar->day[row][6] < 15 && row > 3 ? 1 : 0) - + calendar->month) % 12 + 1, calendar->day[row][6])); - - g_snprintf (buffer, sizeof (buffer), "%d", week); - pango_layout_set_text (layout, buffer, -1); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - /* Hildon: draw passive focus for week */ - if (calendar->focus_row == row) - { - guint y = top_y_for_row (calendar, calendar->focus_row + 1); - - gtk_paint_box(GTK_WIDGET (calendar)->style, - private_data->week_win, - GTK_STATE_NORMAL, - GTK_SHADOW_OUT, NULL, - GTK_WIDGET (calendar), "passive-focus", - 0, y, - private_data->week_width/* - 4*/, - HILDON_DAY_HEIGHT); - } - - y_loc = private_data->day_name_h + top_y_for_row (calendar, row) + (HILDON_DAY_HEIGHT - logical_rect.height) / 2; - x_loc = (HILDON_DAY_WIDTH - logical_rect.width) / 2; - - gdk_draw_layout (private_data->week_win, gc, x_loc, y_loc, layout); - } - - g_object_unref (layout); -} - -static void -hildon_calendar_paint_day_num (GtkWidget *widget, - gint day) -{ - HildonCalendar *calendar; - gint r, c, row, col; - HildonCalendarPrivate *private_data; - g_return_if_fail (HILDON_IS_CALENDAR (widget)); - - calendar = HILDON_CALENDAR (widget); - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - row = -1; - col = -1; - for (r = 0; r < 6; r++) - for (c = 0; c < 7; c++) - if (calendar->day_month[r][c] == MONTH_CURRENT && - calendar->day[r][c] == day) - { - row = r; - col = c; - } - - g_return_if_fail (row != -1); - g_return_if_fail (col != -1); - - hildon_calendar_paint_day (widget, row, col); -} - -static void -hildon_calendar_paint_day (GtkWidget *widget, - gint row, - gint col) -{ - HildonCalendar *calendar; - GdkGC *gc; - gchar buffer[255]; - gint day; - gint x_left; - gint x_loc; - gint y_top; - gint y_loc; - gint focus_width; - - HildonCalendarPrivate *private_data; - PangoLayout *layout; - PangoRectangle logical_rect; - - g_return_if_fail (HILDON_IS_CALENDAR (widget)); - g_return_if_fail (row < 6); - g_return_if_fail (col < 7); - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (private_data->main_win == NULL) return; - - /* - * Handle freeze/thaw functionality - */ - - if (private_data->freeze_count) - { - private_data->dirty_main = 1; - return; - } - - gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL); - - day = calendar->day[row][col]; - x_left = left_x_for_column (calendar, col); - y_top = top_y_for_row (calendar, row); - - gdk_window_clear_area (private_data->main_win, x_left, y_top, - HILDON_DAY_WIDTH, HILDON_DAY_HEIGHT); - - gc = calendar->gc; - - if (calendar->day_month[row][col] == MONTH_PREV) - { - gdk_gc_set_foreground (gc, PREV_MONTH_COLOR (GTK_WIDGET (calendar))); - } - else if (calendar->day_month[row][col] == MONTH_NEXT) - { - gdk_gc_set_foreground (gc, NEXT_MONTH_COLOR (GTK_WIDGET (calendar))); - } - else - { - if (calendar->selected_day == day) - { - /* Hildon: use custom graphics */ - gtk_paint_box(GTK_WIDGET (calendar)->style, - private_data->main_win, - GTK_STATE_NORMAL, - GTK_SHADOW_NONE, NULL, - GTK_WIDGET (calendar), "active-day", - x_left, y_top, - HILDON_DAY_WIDTH, - HILDON_DAY_HEIGHT); - } - if (calendar->marked_date[day-1]) - gdk_gc_set_foreground (gc, MARKED_COLOR (GTK_WIDGET (calendar))); - else - gdk_gc_set_foreground (gc, NORMAL_DAY_COLOR (GTK_WIDGET (calendar))); - if (calendar->selected_day == day) - gdk_gc_set_foreground (gc, SELECTED_FG_COLOR (GTK_WIDGET (calendar))); - else - gdk_gc_set_foreground (gc, & (GTK_WIDGET (calendar)->style->fg[GTK_WIDGET_STATE (calendar)])); - } - - if (GTK_WIDGET_HAS_FOCUS (calendar) && - calendar->focus_row == row && - calendar->focus_col == col) - { - GtkStateType state; - - if (calendar->selected_day == day) - state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE; - else - state = GTK_STATE_NORMAL; - - gtk_paint_focus (widget->style, - private_data->main_win, - (calendar->selected_day == day) - ? GTK_STATE_SELECTED : GTK_STATE_NORMAL, - NULL, widget, "calendar-day", - x_left, y_top, - HILDON_DAY_WIDTH, - HILDON_DAY_HEIGHT); - } - - /* Hildon: paint green indicator for current day */ - if ((day == private_data->current_day && calendar->selected_day != - private_data->current_day) && (calendar->day_month[row][col] == MONTH_CURRENT)) - hildon_calendar_check_current_date (calendar, x_left, y_top); - - g_snprintf (buffer, sizeof (buffer), "%d", day); - layout = gtk_widget_create_pango_layout (widget, buffer); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - x_loc = x_left + (HILDON_DAY_WIDTH - logical_rect.width) / 2; - y_loc = y_top + (HILDON_DAY_HEIGHT - logical_rect.height) / 2; - - gdk_draw_layout (private_data->main_win, gc, - x_loc, y_loc, layout); - if (calendar->marked_date[day-1] && - calendar->day_month[row][col] == MONTH_CURRENT) - gdk_draw_layout (private_data->main_win, gc, - x_loc-1, y_loc, layout); - - g_object_unref (layout); -} - -static void -hildon_calendar_paint_main (GtkWidget *widget) -{ - HildonCalendarPrivate *private_data; - gint row, col; - - g_return_if_fail (HILDON_IS_CALENDAR (widget)); - g_return_if_fail (widget->window != NULL); - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (private_data->freeze_count) - { - private_data->dirty_main = 1; - return; - } - private_data->dirty_main = 0; - gdk_window_clear (private_data->main_win); - - for (col = 0; col < 7; col++) - for (row = 0; row < 6; row++) - hildon_calendar_paint_day (widget, row, col); -} - -static void -hildon_calendar_compute_days (HildonCalendar *calendar) -{ - HildonCalendarPrivate *private_data; - gint month; - gint year; - gint ndays_in_month; - gint ndays_in_prev_month; - gint first_day; - gint row; - gint col; - gint day; - - g_return_if_fail (HILDON_IS_CALENDAR (calendar)); - - private_data = HILDON_CALENDAR_GET_PRIVATE (GTK_WIDGET (calendar)); - - year = calendar->year; - month = calendar->month + 1; - - ndays_in_month = month_length[leap (year)][month]; - - first_day = day_of_week (year, month, 1); - first_day = (first_day + 7 - private_data->week_start) % 7; - - /* Compute days of previous month */ - if (month > 1) - ndays_in_prev_month = month_length[leap (year)][month-1]; - else - ndays_in_prev_month = month_length[leap (year)][12]; - day = ndays_in_prev_month - first_day + 1; - - row = 0; - if (first_day > 0) - { - for (col = 0; col < first_day; col++) - { - calendar->day[row][col] = day; - calendar->day_month[row][col] = MONTH_PREV; - day++; - } - } - - /* Compute days of current month */ - col = first_day; - for (day = 1; day <= ndays_in_month; day++) - { - calendar->day[row][col] = day; - calendar->day_month[row][col] = MONTH_CURRENT; - - col++; - if (col == 7) - { - row++; - col = 0; - } - } - - /* Compute days of next month */ - day = 1; - for (; row <= 5; row++) - { - for (; col <= 6; col++) - { - calendar->day[row][col] = day; - calendar->day_month[row][col] = MONTH_NEXT; - day++; - } - col = 0; - } -} - -/** - * hildon_calendar_get_display_options: - * @calendar: a #HildonCalendar - * - * Returns the current display options of @calendar. - * - * Return value: the display options. - **/ -HildonCalendarDisplayOptions -hildon_calendar_get_display_options (HildonCalendar *calendar) -{ - g_return_val_if_fail (HILDON_IS_CALENDAR (calendar), 0); - - return calendar->display_flags; -} - -/** - * hildon_calendar_set_display_options: - * @calendar: a #HildonCalendar - * @flags: the display options to set - * - * Sets display options (whether to display the heading and the month - * headings). - * - **/ -void -hildon_calendar_set_display_options (HildonCalendar *calendar, - HildonCalendarDisplayOptions flags) -{ - HildonCalendarPrivate *private_data; - gint resize = 0; - GtkWidget *widget; - gint i; - HildonCalendarDisplayOptions old_flags; - - g_return_if_fail (HILDON_IS_CALENDAR (calendar)); - - widget = GTK_WIDGET (calendar); - private_data = HILDON_CALENDAR_GET_PRIVATE (calendar); - old_flags = calendar->display_flags; - - if (GTK_WIDGET_REALIZED (widget)) - { - if ((flags ^ calendar->display_flags) & HILDON_CALENDAR_NO_MONTH_CHANGE) - { - resize ++; - if (! (flags & HILDON_CALENDAR_NO_MONTH_CHANGE) - && (private_data->header_win)) - { - calendar->display_flags &= ~HILDON_CALENDAR_NO_MONTH_CHANGE; - hildon_calendar_realize_arrows (widget); - } - else - { - for (i = 0; i < 4; i++) - { - if (private_data->arrow_win[i]) - { - gdk_window_set_user_data (private_data->arrow_win[i], - NULL); - gdk_window_destroy (private_data->arrow_win[i]); - private_data->arrow_win[i] = NULL; - } - } - } - } - - if ((flags ^ calendar->display_flags) & HILDON_CALENDAR_SHOW_HEADING) - { - resize++; - - if (flags & HILDON_CALENDAR_SHOW_HEADING) - { - calendar->display_flags |= HILDON_CALENDAR_SHOW_HEADING; - hildon_calendar_realize_header (widget); - } - else - { - for (i = 0; i < 4; i++) - { - if (private_data->arrow_win[i]) - { - gdk_window_set_user_data (private_data->arrow_win[i], - NULL); - gdk_window_destroy (private_data->arrow_win[i]); - private_data->arrow_win[i] = NULL; - } - } - gdk_window_set_user_data (private_data->header_win, NULL); - gdk_window_destroy (private_data->header_win); - private_data->header_win = NULL; - } - } - - - if ((flags ^ calendar->display_flags) & HILDON_CALENDAR_SHOW_DAY_NAMES) - { - resize++; - - if (flags & HILDON_CALENDAR_SHOW_DAY_NAMES) - { - calendar->display_flags |= HILDON_CALENDAR_SHOW_DAY_NAMES; - hildon_calendar_realize_day_names (widget); - } - else - { - gdk_window_set_user_data (private_data->day_name_win, NULL); - gdk_window_destroy (private_data->day_name_win); - private_data->day_name_win = NULL; - } - } - - if ((flags ^ calendar->display_flags) & HILDON_CALENDAR_SHOW_WEEK_NUMBERS) - { - resize++; - - if (flags & HILDON_CALENDAR_SHOW_WEEK_NUMBERS) - { - calendar->display_flags |= HILDON_CALENDAR_SHOW_WEEK_NUMBERS; - hildon_calendar_realize_week_numbers (widget); - } - else - { - gdk_window_set_user_data (private_data->week_win, NULL); - gdk_window_destroy (private_data->week_win); - private_data->week_win = NULL; - } - } - - if ((flags ^ calendar->display_flags) & HILDON_CALENDAR_WEEK_START_MONDAY) - g_warning ("HILDON_CALENDAR_WEEK_START_MONDAY is ignored; the first day of the week is determined from the locale"); - - calendar->display_flags = flags; - if (resize) - gtk_widget_queue_resize (GTK_WIDGET (calendar)); - - } - else - calendar->display_flags = flags; - - g_object_freeze_notify (G_OBJECT (calendar)); - if ((old_flags ^ calendar->display_flags) & HILDON_CALENDAR_SHOW_HEADING) - g_object_notify (G_OBJECT (calendar), "show-heading"); - if ((old_flags ^ calendar->display_flags) & HILDON_CALENDAR_SHOW_DAY_NAMES) - g_object_notify (G_OBJECT (calendar), "show-day-names"); - if ((old_flags ^ calendar->display_flags) & HILDON_CALENDAR_NO_MONTH_CHANGE) - g_object_notify (G_OBJECT (calendar), "no-month-change"); - if ((old_flags ^ calendar->display_flags) & HILDON_CALENDAR_SHOW_WEEK_NUMBERS) - g_object_notify (G_OBJECT (calendar), "show-week-numbers"); - g_object_thaw_notify (G_OBJECT (calendar)); -} - -gboolean -hildon_calendar_select_month (HildonCalendar *calendar, - guint month, - guint year) -{ - HildonCalendarPrivate *priv; - - g_return_val_if_fail (HILDON_IS_CALENDAR (calendar), FALSE); - g_return_val_if_fail (month <= 11, FALSE); - - priv = HILDON_CALENDAR_GET_PRIVATE (calendar); - - if (priv->max_year && year > priv->max_year) - year = priv->max_year; - if (priv->min_year && year < priv->min_year) - year = priv->min_year; - - calendar->month = month; - calendar->year = year; - - hildon_calendar_compute_days (calendar); - - gtk_widget_queue_draw (GTK_WIDGET (calendar)); - - g_object_freeze_notify (G_OBJECT (calendar)); - g_object_notify (G_OBJECT (calendar), "month"); - g_object_notify (G_OBJECT (calendar), "year"); - g_object_thaw_notify (G_OBJECT (calendar)); - - g_signal_emit (calendar, - hildon_calendar_signals[MONTH_CHANGED_SIGNAL], - 0); - return TRUE; -} - -void -hildon_calendar_select_day (HildonCalendar *calendar, - guint day) -{ - gint row, col; - HildonCalendarPrivate *priv; - g_return_if_fail (HILDON_IS_CALENDAR (calendar)); - g_return_if_fail (day <= 31); - priv = HILDON_CALENDAR_GET_PRIVATE (calendar); - - for (row = 0; row < 6; row ++) - for (col = 0; col < 7; col++) - { - if (calendar->day_month[row][col] == MONTH_CURRENT - && calendar->day[row][col] == day) - { - calendar->focus_row = row; - calendar->focus_col = col; - } - } - - if (calendar->month != priv->current_month || - calendar->year != priv->current_year) - hildon_calendar_unmark_day (calendar, priv->current_day); - - /* Deselect the old day */ - if (calendar->selected_day > 0) - { - gint selected_day; - - selected_day = calendar->selected_day; - calendar->selected_day = 0; - if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar))) - { - hildon_calendar_paint_day_num (GTK_WIDGET (calendar), selected_day); - } - } - - calendar->selected_day = day; - - /*printf("Selected day = %d\n", day);*/ - - /* Select the new day */ - if (day != 0) - { - if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar))) - { - hildon_calendar_paint_day_num (GTK_WIDGET (calendar), day); - } - } - - g_object_notify (G_OBJECT (calendar), "day"); - g_signal_emit (calendar, - hildon_calendar_signals[DAY_SELECTED_SIGNAL], - 0); -} - -static void -hildon_calendar_select_and_focus_day (HildonCalendar *calendar, - guint day) -{ - gint old_focus_row = calendar->focus_row; - gint old_focus_col = calendar->focus_col; - gint row; - gint col; - - for (row = 0; row < 6; row ++) - for (col = 0; col < 7; col++) - { - if (calendar->day_month[row][col] == MONTH_CURRENT - && calendar->day[row][col] == day) - { - calendar->focus_row = row; - calendar->focus_col = col; - } - } - - if (old_focus_row != -1 && old_focus_col != -1) - hildon_calendar_paint_day (GTK_WIDGET (calendar), old_focus_row, old_focus_col); - - hildon_calendar_select_day (calendar, day); -} - -void -hildon_calendar_clear_marks (HildonCalendar *calendar) -{ - guint day; - - g_return_if_fail (HILDON_IS_CALENDAR (calendar)); - - for (day = 0; day < 31; day++) - { - calendar->marked_date[day] = FALSE; - } - - calendar->num_marked_dates = 0; - - if (GTK_WIDGET_DRAWABLE (calendar)) - { - hildon_calendar_paint_main (GTK_WIDGET (calendar)); - } -} - -gboolean -hildon_calendar_mark_day (HildonCalendar *calendar, - guint day) -{ - g_return_val_if_fail (HILDON_IS_CALENDAR (calendar), FALSE); - if (day >= 1 && day <= 31 && calendar->marked_date[day-1] == FALSE) - { - calendar->marked_date[day - 1] = TRUE; - calendar->num_marked_dates++; - - if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar))) - hildon_calendar_paint_day_num (GTK_WIDGET (calendar), day-1); - } - - return TRUE; -} - -gboolean -hildon_calendar_unmark_day (HildonCalendar *calendar, - guint day) -{ - g_return_val_if_fail (HILDON_IS_CALENDAR (calendar), FALSE); - - if (day >= 1 && day <= 31 && calendar->marked_date[day-1] == TRUE) - { - calendar->marked_date[day - 1] = FALSE; - calendar->num_marked_dates--; - - if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar))) - hildon_calendar_paint_day_num (GTK_WIDGET (calendar), day-1); - } - - return TRUE; -} - -void -hildon_calendar_get_date (HildonCalendar *calendar, - guint *year, - guint *month, - guint *day) -{ - g_return_if_fail (HILDON_IS_CALENDAR (calendar)); - - if (year) - *year = calendar->year; - - if (month) - *month = calendar->month; - - if (day) - *day = calendar->selected_day; -} - -static void -arrow_action (HildonCalendar *calendar, - guint arrow) -{ - switch (arrow) - { - case ARROW_YEAR_LEFT: - hildon_calendar_set_year_prev (calendar); - break; - case ARROW_YEAR_RIGHT: - hildon_calendar_set_year_next (calendar); - break; - case ARROW_MONTH_LEFT: - hildon_calendar_set_month_prev (calendar); - break; - case ARROW_MONTH_RIGHT: - hildon_calendar_set_month_next (calendar); - break; - default:; - /* do nothing */ - } - - hildon_calendar_select_and_focus_day(calendar, calendar->selected_day); -} - -static gboolean -calendar_timer (gpointer data) -{ - HildonCalendar *calendar = data; - HildonCalendarPrivate *private_data = HILDON_CALENDAR_GET_PRIVATE (calendar); - gboolean retval = FALSE; - GtkSettings *settings; - guint timeout; - - gdk_window_process_updates (((GtkWidget *) calendar)->window, TRUE); - - settings = gtk_settings_get_default (); - g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL); - timeout *= 8; - - if (private_data->timer) - { - arrow_action (calendar, private_data->click_child); - - if (private_data->need_timer) - { - private_data->need_timer = FALSE; - private_data->timer = gdk_threads_add_timeout (/*CALENDAR_TIMER_DELAY*/timeout, - (GSourceFunc) calendar_timer, - (gpointer) calendar); - } - else - retval = TRUE; - } - - return retval; -} - -static void -start_spinning (GtkWidget *widget, - gint click_child) -{ - HildonCalendarPrivate *private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - GtkSettings *settings; - guint timeout; - - settings = gtk_settings_get_default (); - g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL); - timeout *= 8; - - private_data->click_child = click_child; - - if (!private_data->timer) - { - private_data->need_timer = TRUE; - private_data->timer = gdk_threads_add_timeout (/*CALENDAR_INITIAL_TIMER_DELAY*/timeout, - calendar_timer, - (gpointer) widget); - } -} - -static void -stop_spinning (GtkWidget *widget) -{ - HildonCalendarPrivate *private_data; - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (private_data->timer) - { - g_source_remove (private_data->timer); - private_data->timer = 0; - private_data->need_timer = FALSE; - } -} - -static void -hildon_calendar_destroy (GtkObject *object) -{ - stop_spinning (GTK_WIDGET (object)); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -hildon_calendar_grab_notify (GtkWidget *widget, - gboolean was_grabbed) -{ - if (!was_grabbed) - stop_spinning (widget); -} - -static gboolean -hildon_calendar_focus_out (GtkWidget *widget, - GdkEventFocus *event) -{ - HildonCalendarPrivate *private_data; - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - stop_spinning (widget); - - private_data->in_drag = 0; - - return FALSE; -} - -static gboolean -hildon_calendar_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - gint arrow = -1; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - - if (event->type == GDK_2BUTTON_PRESS) - { - if (event->window == private_data->main_win) - hildon_calendar_main_button (widget, event); - } - else if (event->window == private_data->main_win) - { - gint x = (gint) (event->x); - gint y = (gint) (event->y); - gint row = row_from_y (calendar, y); - gint col = column_from_x (calendar, x); - private_data->pressed_day = calendar->day[row][col]; - - if ((calendar->year == private_data->min_year && - calendar->month == 0 - && calendar->day_month[row][col] == MONTH_PREV) || - (calendar->year == private_data->max_year && - calendar->month == 11 && - calendar->day_month[row][col] == MONTH_NEXT)) - {} - else if (calendar->day_month[row][col] == MONTH_CURRENT) - hildon_calendar_select_and_focus_day (calendar, private_data->pressed_day); - - /* Remember month where button was pressed */ - private_data->pressed_month = calendar->month; - private_data->slide_stylus = TRUE; - } - - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - - for (arrow = ARROW_YEAR_LEFT; arrow <= ARROW_MONTH_RIGHT; arrow++) - { - if (event->window == private_data->arrow_win[arrow]) - { - - /* only call the action on single click, not double */ - if (event->type == GDK_BUTTON_PRESS) - { - if (event->button == 1) - start_spinning (widget, arrow); - - arrow_action (calendar, arrow); - } - - return TRUE; - } - } - - return TRUE; -} - -static gboolean -hildon_calendar_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (event->window == private_data->main_win) - { - hildon_calendar_main_button (widget, event); - gint x = (gint) (event->x); - gint y = (gint) (event->y); - gint row = row_from_y (calendar, y); - gint col = column_from_x (calendar, x); - private_data->prev_col = -1; - private_data->prev_row = -1; - - if ((private_data->pressed_day == calendar->day[row][col]) && - (private_data->pressed_month == calendar->month)) - { - if (!private_data->is_bad_day) - { - g_signal_emit (calendar, hildon_calendar_signals[SELECTED_DATE_SIGNAL], 0); - } - else - { - private_data->is_bad_day = FALSE; - } - } - } - - if (event->button == 1) - { - stop_spinning (widget); - - if (private_data->in_drag) - private_data->in_drag = 0; - } - - private_data->slide_stylus = FALSE; - return TRUE; -} - -static gboolean -hildon_calendar_motion_notify (GtkWidget *widget, - GdkEventMotion *event) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - gint event_x, event_y; - gint row, col; - gint old_row, old_col; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - event_x = (gint) (event->x); - event_y = (gint) (event->y); - - if (event->window == private_data->main_win) - { - /* Hildon: make active day to move, when stylus is slided */ - if (private_data->slide_stylus) - { - gint c_row = row_from_y (calendar, event_y); - gint c_col = column_from_x (calendar, event_x); - - if (calendar->day_month[c_row][c_col] == MONTH_PREV || - calendar->day_month[c_row][c_col] == MONTH_NEXT) - { } - else if ((private_data->prev_row != c_row || private_data->prev_col != c_col) && - (calendar->highlight_row != -1 && calendar->highlight_col != -1)) - { - hildon_calendar_select_and_focus_day (calendar, - calendar->day[c_row][c_col]); - /* Update passive focus indicators work weekday number and name */ - hildon_calendar_paint_week_numbers (GTK_WIDGET (calendar)); - hildon_calendar_paint_day_names (GTK_WIDGET (calendar)); - } - private_data->prev_col = c_col; - private_data->prev_row = c_row; - } - if (private_data->in_drag) - { - if (gtk_drag_check_threshold (widget, - private_data->drag_start_x, private_data->drag_start_y, - event->x, event->y)) - { - GdkDragContext *context; - GtkTargetList *target_list = gtk_target_list_new (NULL, 0); - gtk_target_list_add_text_targets (target_list, 0); - context = gtk_drag_begin (widget, target_list, GDK_ACTION_COPY, - 1, (GdkEvent *)event); - - - private_data->in_drag = 0; - - gtk_target_list_unref (target_list); - gtk_drag_set_icon_default (context); - } - } - else - { - row = row_from_y (calendar, event_y); - col = column_from_x (calendar, event_x); - - if (row != calendar->highlight_row || calendar->highlight_col != col) - { - old_row = calendar->highlight_row; - old_col = calendar->highlight_col; - if (old_row > -1 && old_col > -1) - { - calendar->highlight_row = -1; - calendar->highlight_col = -1; - hildon_calendar_paint_day (widget, old_row, old_col); - } - - calendar->highlight_row = row; - calendar->highlight_col = col; - - if (row > -1 && col > -1) - hildon_calendar_paint_day (widget, row, col); - } - } - } - - return TRUE; -} - -static gboolean -hildon_calendar_enter_notify (GtkWidget *widget, - GdkEventCrossing *event) -{ - HildonCalendarPrivate *private_data; - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (event->window == private_data->arrow_win[ARROW_MONTH_LEFT]) - { - private_data->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_PRELIGHT; - hildon_calendar_paint_arrow (widget, ARROW_MONTH_LEFT); - } - - if (event->window == private_data->arrow_win[ARROW_MONTH_RIGHT]) - { - private_data->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_PRELIGHT; - hildon_calendar_paint_arrow (widget, ARROW_MONTH_RIGHT); - } - - if (event->window == private_data->arrow_win[ARROW_YEAR_LEFT]) - { - private_data->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_PRELIGHT; - hildon_calendar_paint_arrow (widget, ARROW_YEAR_LEFT); - } - - if (event->window == private_data->arrow_win[ARROW_YEAR_RIGHT]) - { - private_data->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_PRELIGHT; - hildon_calendar_paint_arrow (widget, ARROW_YEAR_RIGHT); - } - - return TRUE; -} - -static gboolean -hildon_calendar_leave_notify (GtkWidget *widget, - GdkEventCrossing *event) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - gint row; - gint col; - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (event->window == private_data->main_win) - { - row = calendar->highlight_row; - col = calendar->highlight_col; - calendar->highlight_row = -1; - calendar->highlight_col = -1; - if (row > -1 && col > -1) - hildon_calendar_paint_day (widget, row, col); - } - - if (event->window == private_data->arrow_win[ARROW_MONTH_LEFT]) - { - private_data->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_NORMAL; - hildon_calendar_paint_arrow (widget, ARROW_MONTH_LEFT); - } - - if (event->window == private_data->arrow_win[ARROW_MONTH_RIGHT]) - { - private_data->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_NORMAL; - hildon_calendar_paint_arrow (widget, ARROW_MONTH_RIGHT); - } - - if (event->window == private_data->arrow_win[ARROW_YEAR_LEFT]) - { - private_data->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_NORMAL; - hildon_calendar_paint_arrow (widget, ARROW_YEAR_LEFT); - } - - if (event->window == private_data->arrow_win[ARROW_YEAR_RIGHT]) - { - private_data->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_NORMAL; - hildon_calendar_paint_arrow (widget, ARROW_YEAR_RIGHT); - } - - return TRUE; -} - -static void -hildon_calendar_paint_arrow (GtkWidget *widget, - guint arrow) -{ - HildonCalendarPrivate *private_data; - GdkWindow *window; - GdkGC *gc; - HildonCalendar *calendar; - gint state; - guint arrow_hlength, arrow_vlength; - /* gint width, height;*/ - - calendar = HILDON_CALENDAR (widget); - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - gtk_widget_style_get (widget, - "scroll-arrow-hlength", &arrow_hlength, - "scroll-arrow-vlength", &arrow_vlength, - NULL); - - if (private_data->freeze_count) - { - private_data->dirty_header = 1; - return; - } - window = private_data->arrow_win[arrow]; - if (window) - { - state = private_data->arrow_state[arrow]; - gc = calendar->gc; - - /* gdk_window_clear (window);*/ - gdk_window_set_background (window, &(widget)->style->bg[state]); - /* gdk_drawable_get_size (window, &width, &height);*/ - /* gdk_window_clear_area (window, - 0,0, - width,height);*/ - - gdk_window_clear(window); - - /* Hildon: added support for dimmed arrows */ - if (((private_data->min_year && calendar->year <= private_data->min_year) || - (private_data->max_year && calendar->year >= private_data->max_year))) - { - if (private_data->min_year && - calendar->year <= private_data->min_year) - { - if (arrow == ARROW_YEAR_LEFT) - gtk_paint_arrow (widget->style, window, GTK_STATE_INSENSITIVE, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_LEFT, TRUE, - 0, 0, arrow_vlength, arrow_hlength); - else if (arrow == ARROW_YEAR_RIGHT || arrow == ARROW_MONTH_RIGHT) - gtk_paint_arrow (widget->style, window, state, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_RIGHT, TRUE, - 0, 0, arrow_vlength, arrow_hlength); - else if (arrow == ARROW_MONTH_LEFT && calendar->month != 0) - gtk_paint_arrow (widget->style, window, state, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_LEFT, TRUE, - 0, 0, arrow_vlength, arrow_hlength); - else if (arrow == ARROW_MONTH_LEFT && !calendar->month) - gtk_paint_arrow (widget->style, window, GTK_STATE_INSENSITIVE, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_LEFT, TRUE, - 0, 0, arrow_vlength, arrow_hlength); - } - else if (private_data->max_year && - calendar->year >= private_data->max_year) - { - if (arrow == ARROW_YEAR_RIGHT) - gtk_paint_arrow (widget->style, window, GTK_STATE_INSENSITIVE, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_RIGHT, TRUE, - 0, 0, arrow_vlength, arrow_hlength); - else if (arrow == ARROW_YEAR_LEFT || arrow == ARROW_MONTH_LEFT) - gtk_paint_arrow (widget->style, window, state, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_LEFT, TRUE, - 0, 0, arrow_vlength, arrow_hlength); - else if (arrow == ARROW_MONTH_RIGHT && calendar->month != 11) - gtk_paint_arrow (widget->style, window, state, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_RIGHT, TRUE, - 0, 0, arrow_vlength, arrow_hlength); - else if (arrow == ARROW_MONTH_RIGHT && calendar->month == 11) - gtk_paint_arrow (widget->style, window, GTK_STATE_INSENSITIVE, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_RIGHT, TRUE, - 0, 0, arrow_vlength, arrow_hlength); - } - } - else - { - if (arrow == ARROW_MONTH_LEFT || arrow == ARROW_YEAR_LEFT) - gtk_paint_arrow (widget->style, window, state, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_LEFT, TRUE, - /* width/2 - 3, height/2 - 4, 8, 8);*/ - 0, 0, arrow_vlength, arrow_hlength); - else - gtk_paint_arrow (widget->style, window, state, - GTK_SHADOW_OUT, NULL, widget, "calendar", - GTK_ARROW_RIGHT, TRUE, - /* width/2 - 2, height/2 - 4, 8, 8);*/ - 0, 0, arrow_vlength, arrow_hlength); - } - } -} - -void -hildon_calendar_freeze (HildonCalendar *calendar) -{ - g_return_if_fail (HILDON_IS_CALENDAR (calendar)); - - HILDON_CALENDAR_GET_PRIVATE (calendar)->freeze_count++; -} - -void -hildon_calendar_thaw (HildonCalendar *calendar) -{ - HildonCalendarPrivate *private_data; - - g_return_if_fail (HILDON_IS_CALENDAR (calendar)); - - private_data = HILDON_CALENDAR_GET_PRIVATE (calendar); - - if (private_data->freeze_count) - if (!(--private_data->freeze_count)) - { - if (private_data->dirty_header) - if (GTK_WIDGET_DRAWABLE (calendar)) - hildon_calendar_paint_header (GTK_WIDGET (calendar)); - - if (private_data->dirty_day_names) - if (GTK_WIDGET_DRAWABLE (calendar)) - hildon_calendar_paint_day_names (GTK_WIDGET (calendar)); - - if (private_data->dirty_week) - if (GTK_WIDGET_DRAWABLE (calendar)) - hildon_calendar_paint_week_numbers (GTK_WIDGET (calendar)); - - if (private_data->dirty_main) - if (GTK_WIDGET_DRAWABLE (calendar)) - hildon_calendar_paint_main (GTK_WIDGET (calendar)); - } -} - -static void -hildon_calendar_set_background (GtkWidget *widget) -{ - HildonCalendarPrivate *private_data; - gint i; - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (GTK_WIDGET_REALIZED (widget)) - { - for (i = 0; i < 4; i++) - { - if (private_data->arrow_win[i]) - gdk_window_set_background (private_data->arrow_win[i], - HEADER_BG_COLOR (widget)); - } - if (private_data->header_win) - gdk_window_set_background (private_data->header_win, - HEADER_BG_COLOR (widget)); - if (private_data->day_name_win) - gdk_window_set_background (private_data->day_name_win, - BACKGROUND_COLOR (widget)); - if (private_data->week_win) - gdk_window_set_background (private_data->week_win, - BACKGROUND_COLOR (widget)); - if (private_data->main_win) - gdk_window_set_background (private_data->main_win, - BACKGROUND_COLOR (widget)); - if (widget->window) - gdk_window_set_background (widget->window, - BACKGROUND_COLOR (widget)); - } -} - -static void -hildon_calendar_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - if (previous_style && GTK_WIDGET_REALIZED (widget)) - hildon_calendar_set_background(widget); -} - -static void -hildon_calendar_state_changed (GtkWidget *widget, - GtkStateType previous_state) -{ - HildonCalendarPrivate *private_data; - int i; - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (!GTK_WIDGET_IS_SENSITIVE (widget)) - { - private_data->in_drag = 0; - stop_spinning (widget); - } - - for (i = 0; i < 4; i++) - if (GTK_WIDGET_IS_SENSITIVE (widget)) - private_data->arrow_state[i] = GTK_STATE_NORMAL; - else - private_data->arrow_state[i] = GTK_STATE_INSENSITIVE; - - hildon_calendar_set_background (widget); -} - -static void -hildon_calendar_finalize (GObject *object) -{ - HildonCalendarPrivate *private_data; - int i; - - private_data = HILDON_CALENDAR_GET_PRIVATE (object); - - for (i = 0; i < 7; i++) - g_free (private_data->abbreviated_dayname[i]); - for (i = 0; i < 12; i++) - g_free (private_data->monthname[i]); - g_free (private_data); - - (* G_OBJECT_CLASS (parent_class)->finalize) (object); -} - -static gboolean -hildon_calendar_scroll (GtkWidget *widget, - GdkEventScroll *event) -{ - HildonCalendar *calendar = HILDON_CALENDAR (widget); - - if (event->direction == GDK_SCROLL_UP) - { - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - hildon_calendar_set_month_prev (calendar); - } - else if (event->direction == GDK_SCROLL_DOWN) - { - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - hildon_calendar_set_month_next (calendar); - } - else - return FALSE; - - return TRUE; -} - -static void -move_focus (HildonCalendar *calendar, - gint direction) -{ - GtkTextDirection text_dir = gtk_widget_get_direction (GTK_WIDGET (calendar)); - - if ((text_dir == GTK_TEXT_DIR_LTR && direction == -1) || - (text_dir == GTK_TEXT_DIR_RTL && direction == 1)) - { - if (calendar->focus_col > 0) - calendar->focus_col--; - else if (calendar->focus_row > 0) - { - calendar->focus_col = 6; - calendar->focus_row--; - } - } - else - { - if (calendar->focus_col < 6) - calendar->focus_col++; - else if (calendar->focus_row < 5) - { - calendar->focus_col = 0; - calendar->focus_row++; - } - } -} - -static gboolean -hildon_calendar_key_press (GtkWidget *widget, - GdkEventKey *event) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *priv; - GtkSettings *settings; - gint return_val; - gint old_focus_row; - gint old_focus_col; - gint row, col, day; - gboolean knav; - - calendar = HILDON_CALENDAR (widget); - priv = HILDON_CALENDAR_GET_PRIVATE (calendar); - return_val = FALSE; - - old_focus_row = calendar->focus_row; - old_focus_col = calendar->focus_col; - - settings = gtk_settings_get_default (); - g_object_get (settings, "hildon-keyboard-navigation", &knav, NULL); - - switch (event->keyval) - { - case GDK_KP_Left: - case GDK_Left: - return_val = TRUE; - if (event->state & GDK_CONTROL_MASK) - hildon_calendar_set_month_prev (calendar); - else - { - /* if we are at the first allowed day of the minimum year/month then do nothing */ - if (calendar->year == priv->min_year && calendar->month == 0 && - calendar->day_month[old_focus_row][old_focus_col-1] == MONTH_PREV) - { - g_signal_emit (calendar, hildon_calendar_signals[ERRONEOUS_DATE_SIGNAL], 0); - return TRUE; - } - else /* else normal */ - { - move_focus (calendar, -1); - if (!knav) - { - hildon_calendar_paint_day (widget, old_focus_row, old_focus_col); - hildon_calendar_paint_day (widget, calendar->focus_row, - calendar->focus_col); - } - else if (knav) - { - gint day_month = calendar->day_month[calendar->focus_row][calendar->focus_col]; - if (day_month == MONTH_CURRENT && calendar->selected_day != 1) - { - hildon_calendar_select_day(calendar, calendar->selected_day - 1); - } - else - { - if (calendar->month != 0) { - calendar->selected_day = month_length[leap (calendar->year)][calendar->month]; - } else { - calendar->selected_day = month_length[leap (calendar->year -1)][12]; - } - hildon_calendar_set_month_prev (calendar); - } - hildon_calendar_paint_week_numbers (GTK_WIDGET (calendar)); - hildon_calendar_paint_day_names (GTK_WIDGET (calendar)); - } - } - } - break; - case GDK_KP_Right: - case GDK_Right: - return_val = TRUE; - if (event->state & GDK_CONTROL_MASK) - hildon_calendar_set_month_next (calendar); - else - { - if (calendar->year == priv->max_year && calendar->month == 11 && - calendar->day_month[old_focus_row][old_focus_col+1] == MONTH_NEXT) - { - g_signal_emit (calendar, hildon_calendar_signals[ERRONEOUS_DATE_SIGNAL], 0); - return TRUE; - } - else - { - move_focus (calendar, 1); - if (!knav) - { - hildon_calendar_paint_day (widget, old_focus_row, old_focus_col); - hildon_calendar_paint_day (widget, calendar->focus_row, - calendar->focus_col); - } - else if (knav) - { - gint day_month = calendar->day_month[calendar->focus_row][calendar->focus_col]; - if (day_month == MONTH_CURRENT) - { - hildon_calendar_select_day (calendar, calendar->selected_day + 1); - } - else - { - calendar->selected_day = 1; - hildon_calendar_set_month_next (calendar); - } - hildon_calendar_paint_week_numbers (GTK_WIDGET (calendar)); - hildon_calendar_paint_day_names (GTK_WIDGET (calendar)); - } - } - } - break; - case GDK_KP_Up: - case GDK_Up: - return_val = TRUE; - if (event->state & GDK_CONTROL_MASK) - hildon_calendar_set_year_prev (calendar); - else - { - if (calendar->year == priv->min_year && calendar->month == 0 && - calendar->day_month[old_focus_row-1][old_focus_col] == MONTH_PREV) - { - g_signal_emit (calendar, hildon_calendar_signals[ERRONEOUS_DATE_SIGNAL], 0); - return TRUE; - } - else - { - if (calendar->focus_row > 0) - calendar->focus_row--; - if (!knav) - { - hildon_calendar_paint_day (widget, old_focus_row, old_focus_col); - hildon_calendar_paint_day (widget, calendar->focus_row, - calendar->focus_col); - } - else if (knav) - { - gint day_month = calendar->day_month[calendar->focus_row][calendar->focus_col]; - if (day_month == MONTH_CURRENT) - { - if ((calendar->selected_day - 7) <= 0) - { - if (calendar->month != 0) - calendar->selected_day = month_length[leap (calendar->year)][calendar->month]; - else - calendar->selected_day = month_length[leap (calendar->year - 1)][12]; - hildon_calendar_set_month_prev (calendar); - } - else - { - hildon_calendar_select_day (calendar, calendar->selected_day - 7); - } - } - else - { - calendar->selected_day = calendar->day[calendar->focus_row][calendar->focus_col]; - hildon_calendar_set_month_prev (calendar); - } - hildon_calendar_paint_week_numbers (GTK_WIDGET (calendar)); - hildon_calendar_paint_day_names (GTK_WIDGET (calendar)); - } - } - } - break; - case GDK_KP_Down: - case GDK_Down: - return_val = TRUE; - if (event->state & GDK_CONTROL_MASK) - hildon_calendar_set_year_next (calendar); - else - { - if (calendar->year == priv->max_year && calendar->month == 11 && - calendar->day_month[old_focus_row+1][old_focus_col] == MONTH_NEXT) - { - g_signal_emit (calendar, hildon_calendar_signals[ERRONEOUS_DATE_SIGNAL], 0); - return TRUE; - } - else - { - - if (calendar->focus_row < 5) - calendar->focus_row++; - if (!knav) - { - hildon_calendar_paint_day (widget, old_focus_row, old_focus_col); - hildon_calendar_paint_day (widget, calendar->focus_row, - calendar->focus_col); - } - else if (knav) - { - gint day_month = calendar->day_month[calendar->focus_row][calendar->focus_col]; - if (day_month == MONTH_CURRENT) - { - if ((calendar->selected_day + 7) > - month_length[leap (calendar->year)][calendar->month + 1]) - { - calendar->selected_day = 1; - hildon_calendar_set_month_next (calendar); - } - else - { - hildon_calendar_select_day (calendar, calendar->selected_day + 7); - } - } - else - { - calendar->selected_day = calendar->day[calendar->focus_row][calendar->focus_col]; - hildon_calendar_set_month_next (calendar); - } - hildon_calendar_paint_week_numbers (GTK_WIDGET (calendar)); - hildon_calendar_paint_day_names (GTK_WIDGET (calendar)); - } - } - } - - break; - case GDK_KP_Space: - case GDK_space: - row = calendar->focus_row; - col = calendar->focus_col; - day = calendar->day[row][col]; - - if (row > -1 && col > -1) - { - return_val = TRUE; - hildon_calendar_freeze (calendar); - - if (calendar->day_month[row][col] == MONTH_PREV) - hildon_calendar_set_month_prev (calendar); - else if (calendar->day_month[row][col] == MONTH_NEXT) - hildon_calendar_set_month_next (calendar); - - hildon_calendar_select_and_focus_day (calendar, day); - - hildon_calendar_thaw (calendar); - } - } - - return return_val; -} - -static void -hildon_calendar_set_display_option (HildonCalendar *calendar, - HildonCalendarDisplayOptions flag, - gboolean setting) -{ - HildonCalendarDisplayOptions flags; - - if (setting) - flags = calendar->display_flags | flag; - else - flags = calendar->display_flags & ~flag; - - hildon_calendar_set_display_options (calendar, flags); -} - -static gboolean -hildon_calendar_get_display_option (HildonCalendar *calendar, - HildonCalendarDisplayOptions flag) -{ - return (calendar->display_flags & flag) != 0; -} - - -static void -hildon_calendar_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - gint val; - - calendar = HILDON_CALENDAR (object); - private_data = HILDON_CALENDAR_GET_PRIVATE (calendar); - - switch (prop_id) - { - case PROP_YEAR: - hildon_calendar_select_month (calendar, - calendar->month, - g_value_get_int (value)); - break; - case PROP_MONTH: - hildon_calendar_select_month (calendar, - g_value_get_int (value), - calendar->year); - break; - case PROP_DAY: - hildon_calendar_select_day (calendar, - g_value_get_int (value)); - break; - case PROP_SHOW_HEADING: - hildon_calendar_set_display_option (calendar, - HILDON_CALENDAR_SHOW_HEADING, - g_value_get_boolean (value)); - break; - case PROP_SHOW_DAY_NAMES: - hildon_calendar_set_display_option (calendar, - HILDON_CALENDAR_SHOW_DAY_NAMES, - g_value_get_boolean (value)); - break; - case PROP_NO_MONTH_CHANGE: - hildon_calendar_set_display_option (calendar, - HILDON_CALENDAR_NO_MONTH_CHANGE, - g_value_get_boolean (value)); - break; - case PROP_SHOW_WEEK_NUMBERS: - hildon_calendar_set_display_option (calendar, - HILDON_CALENDAR_SHOW_WEEK_NUMBERS, - g_value_get_boolean (value)); - break; - case PROP_WEEK_START: - private_data->week_start = g_value_get_int (value); - break; - case PROP_MIN_YEAR: - val = g_value_get_int (value); - if (val <= private_data->max_year || - val == 0 || private_data->max_year == 0) - { - private_data->min_year = val; - if (val && (calendar->year < val)) - hildon_calendar_select_month (calendar, - calendar->month, - private_data->min_year); - } - else - g_warning("min-year cannot be greater than max-year"); - break; - case PROP_MAX_YEAR: - val = g_value_get_int (value); - if (val >= private_data->min_year || - val == 0 || private_data->min_year == 0) - { - private_data->max_year = val; - if (val && (calendar->year > val)) - hildon_calendar_select_month (calendar, - calendar->month, - private_data->max_year); - } - else - g_warning("max-year cannot be less than min-year"); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_calendar_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - HildonCalendar *calendar; - HildonCalendarPrivate *private_data; - - calendar = HILDON_CALENDAR (object); - private_data = HILDON_CALENDAR_GET_PRIVATE (calendar); - - switch (prop_id) - { - case PROP_YEAR: - g_value_set_int (value, calendar->year); - break; - case PROP_MONTH: - g_value_set_int (value, calendar->month); - break; - case PROP_DAY: - g_value_set_int (value, calendar->selected_day); - break; - case PROP_SHOW_HEADING: - g_value_set_boolean (value, hildon_calendar_get_display_option (calendar, - HILDON_CALENDAR_SHOW_HEADING)); - break; - case PROP_SHOW_DAY_NAMES: - g_value_set_boolean (value, hildon_calendar_get_display_option (calendar, - HILDON_CALENDAR_SHOW_DAY_NAMES)); - break; - case PROP_NO_MONTH_CHANGE: - g_value_set_boolean (value, hildon_calendar_get_display_option (calendar, - HILDON_CALENDAR_NO_MONTH_CHANGE)); - break; - case PROP_SHOW_WEEK_NUMBERS: - g_value_set_boolean (value, hildon_calendar_get_display_option (calendar, - HILDON_CALENDAR_SHOW_WEEK_NUMBERS)); - break; - case PROP_WEEK_START: - g_value_set_int (value, private_data->week_start); - break; - case PROP_MIN_YEAR: - g_value_set_int (value, private_data->min_year); - break; - case PROP_MAX_YEAR: - g_value_set_int (value, private_data->max_year); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } - -} - -static void -hildon_calendar_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time) -{ - HildonCalendar *calendar = HILDON_CALENDAR (widget); - GDate *date; - gchar str[128]; - gsize len; - - date = g_date_new_dmy (calendar->selected_day, calendar->month + 1, calendar->year); - len = g_date_strftime (str, 127, "%x", date); - gtk_selection_data_set_text (selection_data, str, len); - - g_free (date); -} - -/* Get/set whether drag_motion requested the drag data and - * drag_data_received should thus not actually insert the data, - * since the data doesn't result from a drop. - */ -static void -set_status_pending (GdkDragContext *context, - GdkDragAction suggested_action) -{ - g_object_set_data (G_OBJECT (context), - "gtk-calendar-status-pending", - GINT_TO_POINTER (suggested_action)); -} - -static GdkDragAction -get_status_pending (GdkDragContext *context) -{ - return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context), - "gtk-calendar-status-pending")); -} - -static void -hildon_calendar_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time) -{ - HildonCalendarPrivate *private_data; - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - private_data->drag_highlight = 0; - gtk_drag_unhighlight (widget); - -} - -static gboolean -hildon_calendar_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time) -{ - HildonCalendarPrivate *private_data; - GdkAtom target; - - private_data = HILDON_CALENDAR_GET_PRIVATE (widget); - - if (!private_data->drag_highlight) - { - private_data->drag_highlight = 1; - gtk_drag_highlight (widget); - } - - target = gtk_drag_dest_find_target (widget, context, NULL); - if (target == GDK_NONE) - gdk_drag_status (context, 0, time); - else { - set_status_pending (context, context->suggested_action); - gtk_drag_get_data (widget, context, target, time); - } - - return TRUE; -} - -static gboolean -hildon_calendar_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time) -{ - GdkAtom target; - - target = gtk_drag_dest_find_target (widget, context, NULL); - if (target != GDK_NONE) - { - gtk_drag_get_data (widget, context, - target, - time); - return TRUE; - } - - return FALSE; -} - -static void -hildon_calendar_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time) -{ - HildonCalendar *calendar = HILDON_CALENDAR (widget); - guint day, month, year; - gchar *str; - GDate *date; - GdkDragAction suggested_action; - - suggested_action = get_status_pending (context); - - if (suggested_action) - { - set_status_pending (context, 0); - - /* We are getting this data due to a request in drag_motion, - * rather than due to a request in drag_drop, so we are just - * supposed to call drag_status, not actually paste in the - * data. - */ - str = (gchar *) gtk_selection_data_get_text (selection_data); - if (str) - { - date = g_date_new (); - g_date_set_parse (date, str); - if (!g_date_valid (date)) - suggested_action = 0; - g_date_free (date); - g_free (str); - } - else - suggested_action = 0; - - gdk_drag_status (context, suggested_action, time); - - return; - } - - date = g_date_new (); - str = (gchar *) gtk_selection_data_get_text (selection_data); - if (str) - { - g_date_set_parse (date, str); - g_free (str); - } - - if (!g_date_valid (date)) - { - g_warning ("Received invalid date data\n"); - g_date_free (date); - gtk_drag_finish (context, FALSE, FALSE, time); - return; - } - - day = g_date_get_day (date); - month = g_date_get_month (date); - year = g_date_get_year (date); - g_date_free (date); - - gtk_drag_finish (context, TRUE, FALSE, time); - - - g_object_freeze_notify (G_OBJECT (calendar)); - if (!(calendar->display_flags & HILDON_CALENDAR_NO_MONTH_CHANGE) - && (calendar->display_flags & HILDON_CALENDAR_SHOW_HEADING)) - hildon_calendar_select_month (calendar, month - 1, year); - hildon_calendar_select_day (calendar, day); - g_object_thaw_notify (G_OBJECT (calendar)); -} - -/* This function return TRUE if we should mark date and FALSE - * otherwise - */ -static void -hildon_calendar_check_current_date (HildonCalendar *calendar, - gint x, - gint y) -{ - HildonCalendarPrivate *private_data; - - private_data = HILDON_CALENDAR_GET_PRIVATE (calendar); - - if (calendar->month == private_data->current_month && - calendar->year == private_data->current_year) - { - gtk_paint_box( GTK_WIDGET (calendar)->style, - private_data->main_win, - GTK_STATE_NORMAL, - GTK_SHADOW_NONE, NULL, - GTK_WIDGET (calendar), "current-day", - x, y, - HILDON_DAY_WIDTH, - HILDON_DAY_HEIGHT); - } -} - -#define __HILDON_CALENDAR_C__ diff --git a/hildon/hildon-calendar.h b/hildon/hildon-calendar.h deleted file mode 100644 index 8bf0d5a..0000000 --- a/hildon/hildon-calendar.h +++ /dev/null @@ -1,180 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * GTK Calendar Widget - * Copyright (C) 1998 Cesar Miquel and Shawn T. Amundson - - * HldonCalendar modifications - * Copyright (C) 2005, 2006 Nokia Corporation. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_CALENDAR_H__ -#define __HILDON_CALENDAR_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_CALENDAR \ - (hildon_calendar_get_type ()) - -#define HILDON_CALENDAR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - HILDON_TYPE_CALENDAR, HildonCalendar)) - -#define HILDON_CALENDAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - HILDON_TYPE_CALENDAR, HildonCalendarClass)) - -#define HILDON_IS_CALENDAR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HILDON_TYPE_CALENDAR)) - -#define HILDON_IS_CALENDAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_CALENDAR)) - -#define HILDON_CALENDAR_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), HILDON_TYPE_CALENDAR, HildonCalendarClass)) - -typedef struct _HildonCalendar HildonCalendar; - -typedef struct _HildonCalendarClass HildonCalendarClass; - -typedef enum -{ - HILDON_CALENDAR_SHOW_HEADING = 1 << 0, - HILDON_CALENDAR_SHOW_DAY_NAMES = 1 << 1, - HILDON_CALENDAR_NO_MONTH_CHANGE = 1 << 2, - HILDON_CALENDAR_SHOW_WEEK_NUMBERS = 1 << 3, - HILDON_CALENDAR_WEEK_START_MONDAY = 1 << 4 -} HildonCalendarDisplayOptions; - -struct _HildonCalendar -{ - GtkWidget widget; - - GtkStyle *header_style; - GtkStyle *label_style; - - gint month; - gint year; - gint selected_day; - - gint day_month[6][7]; - gint day[6][7]; - - gint num_marked_dates; - gint marked_date[31]; - HildonCalendarDisplayOptions display_flags; - GdkColor marked_date_color[31]; - - GdkGC *gc; - GdkGC *xor_gc; - - gint focus_row; - gint focus_col; - - gint highlight_row; - gint highlight_col; - - gpointer private_data; - gchar grow_space [32]; - - /* Padding for future expansion */ - void (*_gtk_reserved1) (void); - void (*_gtk_reserved2) (void); - void (*_gtk_reserved3) (void); - void (*_gtk_reserved4) (void); -}; - -struct _HildonCalendarClass -{ - GtkWidgetClass parent_class; - - /* Signal handlers */ - void (* month_changed) (HildonCalendar *calendar); - void (* day_selected) (HildonCalendar *calendar); - void (* day_selected_double_click) (HildonCalendar *calendar); - void (* prev_month) (HildonCalendar *calendar); - void (* next_month) (HildonCalendar *calendar); - void (* prev_year) (HildonCalendar *calendar); - void (* next_year) (HildonCalendar *calendar); -}; - - -GType G_GNUC_CONST -hildon_calendar_get_type (void); - -GtkWidget* -hildon_calendar_new (void); - -gboolean -hildon_calendar_select_month (HildonCalendar *calendar, - guint month, - guint year); - -void -hildon_calendar_select_day (HildonCalendar *calendar, - guint day); - -gboolean -hildon_calendar_mark_day (HildonCalendar *calendar, - guint day); - -gboolean -hildon_calendar_unmark_day (HildonCalendar *calendar, - guint day); - -void -hildon_calendar_clear_marks (HildonCalendar *calendar); - -void -hildon_calendar_set_display_options (HildonCalendar *calendar, - HildonCalendarDisplayOptions flags); - -HildonCalendarDisplayOptions -hildon_calendar_get_display_options (HildonCalendar *calendar); - -void -hildon_calendar_get_date (HildonCalendar *calendar, - guint *year, - guint *month, - guint *day); - -void -hildon_calendar_freeze (HildonCalendar *calendar); - -void -hildon_calendar_thaw (HildonCalendar *calendar); - -G_END_DECLS - -#endif /* __HILDON_CALENDAR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-code-dialog-private.h b/hildon/hildon-code-dialog-private.h deleted file mode 100644 index fa94638..0000000 --- a/hildon/hildon-code-dialog-private.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_CODE_DIALOG_PRIVATE_H__ -#define __HILDON_CODE_DIALOG_PRIVATE_H__ - -G_BEGIN_DECLS - -#define HILDON_CODE_DIALOG_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_CODE_DIALOG, HildonCodeDialogPrivate)); - -typedef struct _HildonCodeDialogPrivate HildonCodeDialogPrivate; - -struct _HildonCodeDialogPrivate -{ - GtkWidget *entry; - GtkWidget *buttons[5][3]; - GtkWidget *help_text; - GtkIMContext *im_context; -}; - -G_END_DECLS - -#endif /* __HILDON_CODE_DIALOG_PRIVATE_H__ */ diff --git a/hildon/hildon-code-dialog.c b/hildon/hildon-code-dialog.c deleted file mode 100644 index 45d987f..0000000 --- a/hildon/hildon-code-dialog.c +++ /dev/null @@ -1,686 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-code-dialog - * @short_description: A keypad-like widget used to enter pincodes. - * - * #HildonCodeDialog displays a keypad that can be used to enter - * numerical pin codes or lock codes. It emits a 'input' signal each time - * an input action is performed on the dialog. - * - */ - -/* FIXME We need property access in this widget */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <libintl.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-code-dialog.h" -#include "hildon-defines.h" -#include "hildon-banner.h" -#include "hildon-stock.h" -#include "hildon-code-dialog-private.h" - -#define HEIGHT (48-HILDON_MARGIN_DEFAULT) - -#define WIDTH (100-HILDON_MARGIN_DEFAULT) - -#define BACKSPACE_ICON "general_backspace" - -#define _(String) \ - dgettext("hildon-libs", String) - -#define c_(String) \ - dgettext("hildon-common-strings", String) - -#define DEVICELOCK_OK HILDON_STOCK_DONE - -#define DEVICELOCK_TITLE dgettext("osso-system-lock", "secu_application_title") - -#define DEVICELOCK_MAX_CHAR_REACHED c_("ckdg_ib_maximum_characters_reached") - -#define MAX_PINCODE_LEN (10) - -static void -hildon_code_dialog_class_init (HildonCodeDialogClass *cd_class); - -static void -hildon_code_dialog_init (HildonCodeDialog *self); - -static void -hildon_code_dialog_realize (GtkWidget *widget); - -static void -hildon_code_dialog_unrealize (GtkWidget *widget); - -static void -hildon_code_dialog_finalize (GObject *object); - -static void -hildon_code_dialog_button_clicked (GtkButton *buttonm, - gpointer user_data); - -static void -hildon_code_dialog_backspace (HildonCodeDialog *dialog); - -static void -hildon_code_dialog_im_commit (GtkIMContext *im_context, - gchar *utf8, - gpointer user_data); - -static void -hildon_code_dialog_insert_text (GtkEditable *editable, - gchar *new_text, - gint new_text_length, - gint *position, - gpointer user_data); - -static gboolean -hildon_code_dialog_key_press_event (GtkWidget *widget, - GdkEventKey *event, - gpointer user_data); - -static void -hildon_code_dialog_real_input (HildonCodeDialog *dialog); - -static void -hildon_code_dialog_input (HildonCodeDialog *dialog); - -static GtkDialogClass* parent_class = NULL; - -static guint input_signal; - -/** - * hildon_code_dialog_get_type: - * - * Initializes and returns the type of a hildon code dialog. - * - * Returns: GType of #HildonCodeDialog - */ -GType G_GNUC_CONST -hildon_code_dialog_get_type (void) -{ - static GType type = 0; - - if (!type) - { - static const GTypeInfo info = - { - sizeof (HildonCodeDialogClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_code_dialog_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonCodeDialog), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_code_dialog_init - }; - type = g_type_register_static (GTK_TYPE_DIALOG, - "HildonCodeDialog", &info, 0); - } - return type; -} - -static void -hildon_code_dialog_class_init (HildonCodeDialogClass *cd_class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (cd_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (cd_class); - - parent_class = GTK_DIALOG_CLASS (g_type_class_peek_parent (cd_class)); - g_type_class_add_private (cd_class, sizeof (HildonCodeDialogPrivate)); - - gobject_class->finalize = hildon_code_dialog_finalize; - - widget_class->realize = hildon_code_dialog_realize; - widget_class->unrealize = hildon_code_dialog_unrealize; - - cd_class->input = hildon_code_dialog_real_input; - - /* FIXME Document this signal! */ - input_signal = g_signal_new("input", - HILDON_TYPE_CODE_DIALOG, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HildonCodeDialogClass, input), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); -} - -static void -hildon_code_dialog_init (HildonCodeDialog *dialog) -{ - HildonCodeDialogPrivate *priv; - gint i, x, y; - GtkWidget *dialog_vbox1 = NULL; - GtkWidget *table = NULL; - GtkWidget *alignment = NULL; - GtkWidget *vbox1 = NULL; - GtkWidget *image1 = NULL; - GtkWidget *dialog_action_area1 = NULL; - GdkGeometry hints; - GtkWidget *okButton; - - priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - const gchar* numstrs[10] = { - "0","1","2","3","4","5","6","7","8","9" - }; - - GdkPixbuf* pixbuf = NULL; - GtkIconTheme* icon_theme = NULL; - GtkIconInfo *icon_info = NULL; - gint base_size = 0; - - /* Set default title */ - gtk_window_set_title (GTK_WINDOW (dialog), DEVICELOCK_TITLE); - - gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG); - gtk_dialog_set_has_separator ((GtkDialog *) dialog, FALSE); - - hints.min_width = -1; - hints.min_height = -1; - hints.max_width = -1; - hints.max_height = -1; - - gtk_window_set_geometry_hints (GTK_WINDOW (dialog), GTK_WIDGET (dialog), &hints, - GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE); - - table = gtk_table_new (4, 3, FALSE); - gtk_table_set_row_spacings (GTK_TABLE (table), HILDON_MARGIN_DEFAULT ); - gtk_table_set_col_spacings (GTK_TABLE (table), HILDON_MARGIN_DEFAULT ); - - dialog_vbox1 = GTK_DIALOG (dialog)->vbox; - vbox1 = gtk_vbox_new (FALSE, 0); - gtk_box_set_spacing (GTK_BOX (vbox1), HILDON_MARGIN_DOUBLE); - - priv->help_text = gtk_label_new (""); - alignment = gtk_alignment_new (0.5,0,1,1); - gtk_container_add (GTK_CONTAINER (alignment), priv->help_text); - - priv->entry = gtk_entry_new (); - - GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (priv->entry), GTK_CAN_FOCUS); - gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry), g_utf8_get_char ("*")); - gtk_entry_set_alignment (GTK_ENTRY (priv->entry), 1.0); - - gtk_editable_set_editable (GTK_EDITABLE (priv->entry),FALSE); - gtk_entry_set_visibility (GTK_ENTRY (priv->entry), FALSE); - - gtk_box_pack_start (GTK_BOX (vbox1), alignment, TRUE,FALSE,0); - gtk_box_pack_start (GTK_BOX (vbox1), priv->entry, TRUE,FALSE,0); - gtk_box_pack_start (GTK_BOX (vbox1), table, FALSE,TRUE,0); - - gtk_box_pack_start (GTK_BOX (dialog_vbox1), vbox1, FALSE,TRUE,0); - - for(i = 1;i <= 3; i++) { - priv->buttons[0][i-1] = gtk_button_new_with_mnemonic (numstrs[i]); - gtk_widget_set_size_request (priv->buttons[0][i-1], WIDTH, HEIGHT); - gtk_table_attach_defaults (GTK_TABLE (table), priv->buttons[0][i-1], - i-1, i, 0, 1); - } - - for(i = 4;i <= 6;i++) { - priv->buttons[1][i-4] = gtk_button_new_with_mnemonic (numstrs[i]); - gtk_widget_set_size_request (priv->buttons[1][i-4], WIDTH, HEIGHT); - gtk_table_attach_defaults (GTK_TABLE (table), priv->buttons[1][i-4], - i-4, i-3, 1, 2); - } - - for(i=7;i<=9;i++) { - priv->buttons[2][i-7] = gtk_button_new_with_mnemonic (numstrs[i]); - gtk_widget_set_size_request (priv->buttons[2][i-7], WIDTH, HEIGHT); - gtk_table_attach_defaults (GTK_TABLE (table), priv->buttons[2][i-7], - i-7, i-6, 2, 3); - } - - priv->buttons[3][0] = priv->buttons[3][1] = - gtk_button_new_with_mnemonic (numstrs[0]); - gtk_widget_set_size_request (priv->buttons[3][0], WIDTH, HEIGHT); - gtk_table_attach (GTK_TABLE (table), priv->buttons[3][0], - 0,2,3,4, (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - - priv->buttons[3][2] = gtk_button_new (); - gtk_widget_set_size_request (priv->buttons[3][2], WIDTH, HEIGHT); - gtk_table_attach_defaults (GTK_TABLE (table), priv->buttons[3][2], - 2, 3, 3, 4); - - icon_theme = gtk_icon_theme_get_default (); - - icon_info = gtk_icon_theme_lookup_icon (icon_theme, BACKSPACE_ICON, 1, - GTK_ICON_LOOKUP_NO_SVG); - base_size = gtk_icon_info_get_base_size (icon_info); - gtk_icon_info_free (icon_info); - icon_info = NULL; - pixbuf = gtk_icon_theme_load_icon (icon_theme, - BACKSPACE_ICON, base_size, - GTK_ICON_LOOKUP_NO_SVG, - NULL); - - image1 = gtk_image_new_from_pixbuf (pixbuf); - g_object_unref (G_OBJECT(pixbuf)); - gtk_container_add (GTK_CONTAINER (priv->buttons[3][2]), image1); - dialog_action_area1 = GTK_DIALOG (dialog)->action_area; - gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), -#if GTK_CHECK_VERSION(2,11,0) || defined(MAEMO_GTK) - GTK_BUTTONBOX_CENTER); -#else - GTK_BUTTONBOX_DEFAULT_STYLE); -#endif - - okButton = gtk_dialog_add_button (GTK_DIALOG (dialog) ,DEVICELOCK_OK, - GTK_RESPONSE_OK); - - gtk_widget_set_sensitive (okButton, FALSE); - - priv->buttons[4][0] = priv->buttons[4][1] = okButton; - - priv->im_context = gtk_im_multicontext_new(); -#ifdef MAEMO_GTK - g_object_set (G_OBJECT (priv->im_context), "hildon-input-mode", - HILDON_GTK_INPUT_MODE_NUMERIC, NULL); -#endif - - /* - Connect signals. - */ - g_signal_connect (G_OBJECT (priv->im_context), "commit", - G_CALLBACK (hildon_code_dialog_im_commit), dialog); - - g_signal_connect (G_OBJECT (priv->entry), "insert_text", - G_CALLBACK (hildon_code_dialog_insert_text), dialog); - - gtk_entry_set_max_length (GTK_ENTRY (priv->entry), MAX_PINCODE_LEN); - - for (x = 0; x < 3; x++) - { - for (y = 0; y < 3; y++) - { - g_signal_connect (G_OBJECT (priv->buttons[x][y]), "clicked", - G_CALLBACK (hildon_code_dialog_button_clicked), dialog); - g_signal_connect (G_OBJECT (priv->buttons[x][y]), "key-press-event", - G_CALLBACK (hildon_code_dialog_key_press_event), dialog); - } - } - - g_signal_connect (G_OBJECT (priv->buttons[3][0]), "clicked", - G_CALLBACK (hildon_code_dialog_button_clicked), dialog); - g_signal_connect (G_OBJECT (priv->buttons[3][0]), "key-press-event", - G_CALLBACK (hildon_code_dialog_key_press_event), dialog); - - g_signal_connect (G_OBJECT (priv->buttons[3][2]), "clicked", - G_CALLBACK (hildon_code_dialog_button_clicked), dialog); - g_signal_connect (G_OBJECT (priv->buttons[3][2]), "key-press-event", - G_CALLBACK (hildon_code_dialog_key_press_event), dialog); - - g_signal_connect (G_OBJECT (okButton), "key-press-event", - G_CALLBACK(hildon_code_dialog_key_press_event), dialog); - - gtk_widget_show_all (GTK_WIDGET (GTK_DIALOG (dialog)->vbox)); -} - -static void -hildon_code_dialog_realize (GtkWidget *widget) -{ - HildonCodeDialog *dialog = HILDON_CODE_DIALOG (widget); - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - - if (GTK_WIDGET_CLASS (parent_class)->realize) - (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); - - gtk_im_context_set_client_window (GTK_IM_CONTEXT (priv->im_context), - GTK_WIDGET (dialog)->window); - gtk_im_context_focus_in (priv->im_context); -} - -static void -hildon_code_dialog_unrealize (GtkWidget *widget) -{ - HildonCodeDialog *dialog = HILDON_CODE_DIALOG (widget); - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - - gtk_im_context_set_client_window (GTK_IM_CONTEXT (priv->im_context), NULL); - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); -} - -static void -hildon_code_dialog_finalize (GObject *object) -{ - HildonCodeDialog *dialog = HILDON_CODE_DIALOG (object); - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - - g_object_unref (priv->im_context); - - G_OBJECT_CLASS(parent_class)->finalize(object); -} - -static void -hildon_code_dialog_backspace (HildonCodeDialog *dialog) -{ - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - gchar *text, *pos; - - g_assert (priv); - - text = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))); - - pos = text; - - while (*pos != '\0') - { - pos ++; - } - - pos = g_utf8_find_prev_char (text, pos); - - if (pos) - { - *pos=0; - } - - gtk_entry_set_text (GTK_ENTRY (priv->entry), text); - - if (*text == 0) - { - gtk_widget_set_sensitive (priv->buttons[4][0], FALSE); - } - - gtk_editable_set_position (GTK_EDITABLE (priv->entry), -1); - - g_free (text); -} - -static void -hildon_code_dialog_button_clicked (GtkButton *button, - gpointer user_data) -{ - HildonCodeDialog *dialog = HILDON_CODE_DIALOG (user_data); - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - const char *number = gtk_button_get_label (button); - - if (number && *number ) - { - gtk_editable_set_editable (GTK_EDITABLE (priv->entry), TRUE); - - g_signal_emit_by_name (GTK_ENTRY (priv->entry)->im_context, "commit", - number); - - gtk_editable_set_editable (GTK_EDITABLE (priv->entry), FALSE); - - gtk_editable_set_position (GTK_EDITABLE (priv->entry), -1); - } - else - { - hildon_code_dialog_backspace (dialog); - } -} - -static void -hildon_code_dialog_im_commit (GtkIMContext *im_context, - gchar *utf8, - gpointer user_data) -{ - HildonCodeDialog *dialog = HILDON_CODE_DIALOG (user_data); - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - gint digit; - - g_assert (priv); - - digit = g_ascii_strtod(utf8, NULL); - - if (g_ascii_isdigit(*utf8)) - { - gtk_editable_set_editable (GTK_EDITABLE (priv->entry), TRUE); - - g_signal_emit_by_name (GTK_ENTRY (priv->entry)->im_context, "commit", - utf8); - - gtk_editable_set_editable (GTK_EDITABLE (priv->entry), FALSE); - - gtk_editable_set_position (GTK_EDITABLE (priv->entry), -1); - } -} - -static void -hildon_code_dialog_insert_text (GtkEditable *editable, - gchar *new_text, - gint new_text_length, - gint *position, - gpointer user_data) -{ - HildonCodeDialog *dialog = HILDON_CODE_DIALOG (user_data); - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - gchar *text = g_strdup(gtk_entry_get_text (GTK_ENTRY (priv->entry))); - glong length = g_utf8_strlen (text, -1); - g_free (text); - g_assert (priv); - - if (length == MAX_PINCODE_LEN) - { - hildon_banner_show_information (GTK_WIDGET (dialog), - NULL, - DEVICELOCK_MAX_CHAR_REACHED); - } - - else if (! length) - { - /* make the Ok button sensitive */ - gtk_widget_set_sensitive (priv->buttons[4][0], TRUE); - } - - hildon_code_dialog_input (dialog); -} - -static gboolean -hildon_code_dialog_key_press_event (GtkWidget *widget, - GdkEventKey *event, - gpointer user_data) -{ - HildonCodeDialog *dialog = HILDON_CODE_DIALOG (user_data); - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - GtkWidget *new_widget = widget; - gint x, y; - - g_assert (priv); - - if (gtk_im_context_filter_keypress (priv->im_context, event)) - return TRUE; - - if (event->keyval == GDK_BackSpace) - { - hildon_code_dialog_backspace (dialog); - return TRUE; - } - - for (x = 0; x < 5; x++) - { - for (y = 0; y < 3; y++) - { - if (priv->buttons[x][y] == widget) - goto found; - } - } - return FALSE; - -found: - - while (new_widget == widget) - { - switch (event->keyval) - { - case GDK_Up: - x = (x+4)%5; - break; - - case GDK_Down: - x = (x+1)%5; - break; - - case GDK_Left: - y = (y+2)%3; - break; - - case GDK_Right: - y = (y+1)%3; - break; - - default: - return FALSE; - } - - new_widget = priv->buttons[x][y]; - } - - gtk_widget_grab_focus (new_widget); - - return TRUE; -} - -/** - * hildon_code_dialog_new: - * - * Use this function to create a new HildonCodeDialog. - * - * Return value: A @HildonCodeDialog. - **/ -GtkWidget* -hildon_code_dialog_new (void) -{ - HildonCodeDialog *dialog = g_object_new (HILDON_TYPE_CODE_DIALOG, NULL); - - return GTK_WIDGET (dialog); -} - -/** - * hildon_code_dialog_get_code: - * @dialog: The #HildonCodeDialog from which to get the entered code - * - * Use this function to access the code entered by the user. - * - * Return value: The entered code. - **/ -const gchar* -hildon_code_dialog_get_code (HildonCodeDialog *dialog) -{ - g_return_val_if_fail (HILDON_IS_CODE_DIALOG (dialog), NULL); - - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - return gtk_entry_get_text (GTK_ENTRY (priv->entry)); -} - -/** - * hildon_code_dialog_clear_code: - * @dialog: The #HildonCodeDialog whose entry should be cleared: - * - * Use this function to clear the user entered code. - **/ -void -hildon_code_dialog_clear_code (HildonCodeDialog *dialog) -{ - g_return_if_fail (HILDON_IS_CODE_DIALOG (dialog)); - - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - gtk_entry_set_text (GTK_ENTRY (priv->entry), ""); - gtk_widget_set_sensitive (priv->buttons[4][0], FALSE); -} - -/** - * hildon_code_dialog_set_help_text: - * @dialog: The #HildonCodeDialog whose entry should be cleared: - * @text: The text to use in the help label. - * - * Use this function to set the text that will be displayd in the - * help label - **/ -void -hildon_code_dialog_set_help_text (HildonCodeDialog *dialog, - const gchar *text) -{ - g_return_if_fail (HILDON_IS_CODE_DIALOG (dialog)); - - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - gtk_label_set_text (GTK_LABEL (priv->help_text), text); -} - -static void -hildon_code_dialog_real_input (HildonCodeDialog *dialog) -{ -} - -static void -hildon_code_dialog_input (HildonCodeDialog *dialog) -{ - /* Emit the signal */ - g_signal_emit (dialog, input_signal, 0); -} - -/** - * hildon_code_dialog_set_input_sensitive - * @dialog: The #HildonCodeDialog whose state is to be changed - * @sensitive: The new state - * - * This function will block or enable the input on the code dialog by - * making the input button sensitive (or not). - **/ -void -hildon_code_dialog_set_input_sensitive (HildonCodeDialog *dialog, - gboolean sensitive) -{ - int i; - int k; - - g_return_if_fail (HILDON_IS_CODE_DIALOG (dialog)); - - HildonCodeDialogPrivate *priv = HILDON_CODE_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - for (i = 0; i < 5; i++) - for (k = 0; k < 3; k++) - if (i != 4 && (k != 0 || k != 2)) - gtk_widget_set_sensitive (priv->buttons [i][k], sensitive); - - gtk_widget_set_sensitive (priv->help_text, sensitive); - gtk_widget_set_sensitive (priv->entry, sensitive); -} diff --git a/hildon/hildon-code-dialog.h b/hildon/hildon-code-dialog.h deleted file mode 100644 index 6fb917d..0000000 --- a/hildon/hildon-code-dialog.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_CODE_DIALOG_H__ -#define __HILDON_CODE_DIALOG_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_CODE_DIALOG \ - (hildon_code_dialog_get_type()) - -#define HILDON_CODE_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_CODE_DIALOG, HildonCodeDialog)) - -#define HILDON_CODE_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_CODE_DIALOG, HildonCodeDialogClass)) - -#define HILDON_IS_CODE_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_CODE_DIALOG)) - -#define HILDON_IS_CODE_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_CODE_DIALOG)) - -#define HILDON_CODE_DIALOG_GET_CLASS(obj) \ - ((HildonCodeDialogClass *) G_OBJECT_GET_CLASS(obj)) - -typedef struct _HildonCodeDialog HildonCodeDialog; - -typedef struct _HildonCodeDialogClass HildonCodeDialogClass; - -struct _HildonCodeDialog -{ - GtkDialog parent; -}; - -struct _HildonCodeDialogClass -{ - GtkDialogClass parent_class; - void (*input) (HildonCodeDialog *dialog); -}; - -GType G_GNUC_CONST -hildon_code_dialog_get_type (void); - -GtkWidget* -hildon_code_dialog_new (void); - -const gchar* -hildon_code_dialog_get_code (HildonCodeDialog *dialog); - -void -hildon_code_dialog_clear_code (HildonCodeDialog *dialog); - -void -hildon_code_dialog_set_help_text (HildonCodeDialog *dialog, - const gchar *text); - -void -hildon_code_dialog_set_input_sensitive (HildonCodeDialog *dialog, - gboolean sensitive); - -G_END_DECLS - -#endif /* __HILDON_CODE_DIALOG_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-color-button-private.h b/hildon/hildon-color-button-private.h deleted file mode 100644 index 10e7741..0000000 --- a/hildon/hildon-color-button-private.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_COLOR_BUTTON_PRIVATE_H__ -#define __HILDON_COLOR_BUTTON_PRIVATE_H__ - -typedef struct _HildonColorButtonPrivate HildonColorButtonPrivate; - -#define HILDON_COLOR_BUTTON_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\ - HILDON_TYPE_COLOR_BUTTON, HildonColorButtonPrivate)); - -struct _HildonColorButtonPrivate -{ - GtkWidget *dialog; - gboolean popped; - - GdkColor color; - GdkGC *gc; -}; - -#endif /* __HILDON_COLOR_BUTTON_PRIVATE_H__ */ diff --git a/hildon/hildon-color-button.c b/hildon/hildon-color-button.c deleted file mode 100644 index a9430ba..0000000 --- a/hildon/hildon-color-button.c +++ /dev/null @@ -1,645 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-color-button - * @short_description: A widget to open HildonColorChooserDialog. - * @see_also: #HildonColorChooserDialog, #HildonColorPopup - * - * HildonColorButton is a widget to open a HildonColorChooserDialog. - * The selected color is shown in the button. - * The selected color is a property of the button. - * The property name is "color" and its type is GtkColor. - * - * <example> - * <title>HildonColorButton example</title> - * <programlisting> - * HildonColorButton *cbutton; - * GtkColor *color; - * <!-- --> - * cbutton = hildon_color_button_new(); - * gtk_object_get( GTK_OBJECT(cbutton), "color", color ); - * </programlisting> - * </example> - * - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gdk/gdkkeysyms.h> - -#include "hildon-color-button.h" -#include "hildon-defines.h" -#include "hildon-color-chooser-dialog.h" -#include "hildon-color-button-private.h" - -#define COLOR_BUTTON_WIDTH 80 - -#define COLOR_BUTTON_HEIGHT 70 - -#define OUTER_BORDER_RED 0 - -#define OUTER_BORDER_BLUE 0 - -#define OUTER_BORDER_GREEN 0 - -#define OUTER_BORDER_THICKNESS 1 - -#define INNER_BORDER_RED 65535 - -#define INNER_BORDER_BLUE 65535 - -#define INNER_BORDER_GREEN 65535 - -#define INNER_BORDER_THICKNESS 2 - -enum -{ - SETUP_DIALOG, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_COLOR, - PROP_POPUP_SHOWN -}; - -static void -hildon_color_button_class_init (HildonColorButtonClass *klass); - -static void -hildon_color_button_init (HildonColorButton *color_button); - -static void -hildon_color_button_finalize (GObject *object); - -static void -hildon_color_button_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_color_button_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void -hildon_color_button_realize (GtkWidget *widget); - -static void -hildon_color_button_unrealize (GtkWidget *widget); - -static void -hildon_color_button_clicked (GtkButton *button); - -static gboolean -hildon_color_button_key_pressed (GtkWidget *button, - GdkEventKey *event, - gpointer data); - -static gint -hildon_color_field_expose_event (GtkWidget *widget, - GdkEventExpose *event, - HildonColorButton *cb); - -static gboolean -hildon_color_button_mnemonic_activate (GtkWidget *widget, - gboolean group_cycling); - -static void -draw_grid (GdkDrawable *drawable, - GdkGC *gc, - int x, - int y, - gint w, - gint h); - -static gpointer parent_class = NULL; -static guint signals [LAST_SIGNAL] = { 0, }; - -/** - * hildon_color_button_get_type: - * - * Initializes and returns the type of a hildon color button. - * - * Returns: GType of #HildonColorButton. - */ -GType G_GNUC_CONST -hildon_color_button_get_type (void) -{ - static GType color_button_type = 0; - - if (! color_button_type) - { - static const GTypeInfo color_button_info = - { - sizeof (HildonColorButtonClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_color_button_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonColorButton), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_color_button_init, - }; - - color_button_type = g_type_register_static (GTK_TYPE_BUTTON, "HildonColorButton", - &color_button_info, 0); - } - - return color_button_type; -} - -static void -hildon_color_button_class_init (HildonColorButtonClass *klass) -{ - GObjectClass *gobject_class; - GtkButtonClass *button_class; - GtkWidgetClass *widget_class; - - gobject_class = G_OBJECT_CLASS (klass); - button_class = GTK_BUTTON_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - gobject_class->get_property = hildon_color_button_get_property; - gobject_class->set_property = hildon_color_button_set_property; - gobject_class->finalize = hildon_color_button_finalize; - widget_class->realize = hildon_color_button_realize; - widget_class->unrealize = hildon_color_button_unrealize; - button_class->clicked = hildon_color_button_clicked; - widget_class->mnemonic_activate = hildon_color_button_mnemonic_activate; - - signals[SETUP_DIALOG] = - g_signal_new ("setup-dialog", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - HILDON_TYPE_COLOR_CHOOSER_DIALOG); - - /** - * HildonColorButton:color: - * - * The currently selected color. - */ - g_object_class_install_property (gobject_class, PROP_COLOR, - g_param_spec_boxed ("color", - "Current Color", - "The selected color", - GDK_TYPE_COLOR, - G_PARAM_READWRITE)); - - /** - * HildonColorButton:popup-shown: - * - * If the color selection dialog is currently popped-up (visible) - */ - g_object_class_install_property (gobject_class, PROP_POPUP_SHOWN, - g_param_spec_boolean ("popup-shown", - "IsPopped", - "If the color selection dialog is popped up", - FALSE, - G_PARAM_READABLE)); - - g_type_class_add_private (gobject_class, sizeof (HildonColorButtonPrivate)); -} - -/* FIXME Draw a dotted grid over the specified area to make it look - * insensitive. Actually, we should generate that pixbuf once and - * just render it over later... */ -static void -draw_grid (GdkDrawable *drawable, - GdkGC *gc, - int x, - int y, - gint w, - gint h) -{ - int currentx; - int currenty; - for (currenty = y; currenty <= h; currenty++) - for (currentx = ((currenty % 2 == 0) ? x : x + 1); currentx <= w; currentx += 2) - gdk_draw_point (drawable, gc, currentx, currenty); -} - -/* Handle exposure events for the color picker's drawing area */ -static gint -hildon_color_field_expose_event (GtkWidget *widget, - GdkEventExpose *event, - HildonColorButton *cb) -{ - HildonColorButtonPrivate *priv = HILDON_COLOR_BUTTON_GET_PRIVATE (cb); - GdkColor outer_border, inner_border; - - g_assert (priv); - - /* Create the outer border color */ - outer_border.pixel = 0; - outer_border.red = OUTER_BORDER_RED; - outer_border.blue = OUTER_BORDER_BLUE; - outer_border.green = OUTER_BORDER_GREEN; - - /* Create the inner border color */ - inner_border.pixel = 0; - inner_border.red = INNER_BORDER_RED; - inner_border.blue = INNER_BORDER_BLUE; - inner_border.green = INNER_BORDER_GREEN; - - /* serve the outer border color to the Graphic Context */ - gdk_gc_set_rgb_fg_color (priv->gc, &outer_border); - /* draw the outer border as a filled rectangle */ - gdk_draw_rectangle (widget->window, - (GTK_WIDGET_IS_SENSITIVE (widget)) ? priv->gc : widget->style->bg_gc [GTK_STATE_INSENSITIVE], - TRUE, - 0, - 0, - widget->allocation.width, - widget->allocation.height); - - /* serve the inner border color to the Graphic Context */ - gdk_gc_set_rgb_fg_color (priv->gc, &inner_border); - - /* draw the inner border as a filled rectangle */ - gdk_draw_rectangle (widget->window, - priv->gc, - TRUE, - OUTER_BORDER_THICKNESS, - OUTER_BORDER_THICKNESS, - widget->allocation.width - (OUTER_BORDER_THICKNESS * 2), - widget->allocation.height - (OUTER_BORDER_THICKNESS * 2)); - - /* serve the actual color to the Graphic Context */ - gdk_gc_set_rgb_fg_color(priv->gc, &priv->color); - - /* draw the actual rectangle */ - gdk_draw_rectangle(widget->window, - priv->gc, - TRUE, - INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS, - INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS, - widget->allocation.width - ((INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS)*2), - widget->allocation.height - ((INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS)*2)); - - if (! GTK_WIDGET_IS_SENSITIVE (widget)) { - draw_grid (GDK_DRAWABLE (widget->window), widget->style->bg_gc [GTK_STATE_INSENSITIVE], - INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS, - INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS, - widget->allocation.width - ((INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS)*2) + 2, - widget->allocation.height - ((INNER_BORDER_THICKNESS + OUTER_BORDER_THICKNESS)*2) + 2); - } - - return FALSE; -} - -static void -hildon_color_button_init (HildonColorButton *cb) -{ - GtkWidget *align; - GtkWidget *drawing_area; - HildonColorButtonPrivate *priv = HILDON_COLOR_BUTTON_GET_PRIVATE (cb); - - priv->dialog = NULL; - priv->gc = NULL; - priv->popped = FALSE; - - gtk_widget_push_composite_child (); - - /* create widgets and pixbuf */ - align = gtk_alignment_new (0.5, 0.5, 0, 0); /* composite widget */ - - drawing_area = gtk_drawing_area_new (); /* composite widget */ - - /* setting minimum sizes */ - gtk_widget_set_size_request (GTK_WIDGET (cb), COLOR_BUTTON_WIDTH, - COLOR_BUTTON_HEIGHT); - - gtk_widget_set_size_request (GTK_WIDGET(drawing_area), - HILDON_ICON_PIXEL_SIZE_FINGER, - HILDON_ICON_PIXEL_SIZE_FINGER); - - /* Connect the callback function for exposure event */ - g_signal_connect (drawing_area, "expose-event", - G_CALLBACK (hildon_color_field_expose_event), cb); - - /* Connect to callback function for key press event */ - g_signal_connect (G_OBJECT(cb), "key-press-event", - G_CALLBACK(hildon_color_button_key_pressed), cb); - - /* packing */ - gtk_container_add (GTK_CONTAINER (align), drawing_area); - gtk_container_add (GTK_CONTAINER (cb), align); - - gtk_widget_show_all (align); - - gtk_widget_pop_composite_child (); -} - -/* Free memory used by HildonColorButton */ -static void -hildon_color_button_finalize (GObject *object) -{ - HildonColorButtonPrivate *priv = HILDON_COLOR_BUTTON_GET_PRIVATE (object); - g_assert (priv); - - if (priv->dialog) - { - gtk_widget_destroy (priv->dialog); - priv->dialog = NULL; - } - - if (G_OBJECT_CLASS (parent_class)->finalize) - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void -hildon_color_button_realize (GtkWidget *widget) -{ - HildonColorButtonPrivate *priv = HILDON_COLOR_BUTTON_GET_PRIVATE (widget); - g_assert (priv); - - GTK_WIDGET_CLASS (parent_class)->realize (widget); - - priv->gc = gdk_gc_new (widget->window); -} - -static void -hildon_color_button_unrealize (GtkWidget *widget) -{ - HildonColorButtonPrivate *priv = HILDON_COLOR_BUTTON_GET_PRIVATE (widget); - g_assert (priv); - - if (priv->gc != NULL) { - g_object_unref (priv->gc); - priv->gc = NULL; - } - - GTK_WIDGET_CLASS (parent_class)->unrealize (widget); -} - -/* Make the widget sensitive with the keyboard event */ -static gboolean -hildon_color_button_mnemonic_activate (GtkWidget *widget, - gboolean group_cycling) -{ - gtk_widget_grab_focus (widget); - return TRUE; -} - -/* Popup a color selector dialog on button click */ -static void -hildon_color_button_clicked (GtkButton *button) -{ - HildonColorButton *cb = HILDON_COLOR_BUTTON (button); - HildonColorButtonPrivate *priv = HILDON_COLOR_BUTTON_GET_PRIVATE (button); - HildonColorChooserDialog *cs_dialog; - - g_assert (priv); - - cs_dialog = (HildonColorChooserDialog *) priv->dialog; - - /* Popup the color selector dialog */ - if (! cs_dialog) - { - /* The dialog hasn't been created yet, do it */ - GtkWidget *parent = gtk_widget_get_toplevel (GTK_WIDGET(cb)); - priv->dialog = hildon_color_chooser_dialog_new (); - cs_dialog = HILDON_COLOR_CHOOSER_DIALOG (priv->dialog); - if (parent) - gtk_window_set_transient_for (GTK_WINDOW (cs_dialog), GTK_WINDOW (parent)); - - g_signal_emit (button, signals[SETUP_DIALOG], 0, priv->dialog); - } - - /* Set the initial color for the color selector dialog */ - hildon_color_chooser_dialog_set_color (cs_dialog, &priv->color); - - /* Update the color for color button if selection was made */ - priv->popped = TRUE; - if (gtk_dialog_run (GTK_DIALOG (cs_dialog)) == GTK_RESPONSE_OK) - { - hildon_color_chooser_dialog_get_color (cs_dialog, &priv->color); - hildon_color_button_set_color (HILDON_COLOR_BUTTON (button), &priv->color); - // FIXME A queue-draw should be enough here (not set needed) - } - - gtk_widget_hide (GTK_WIDGET(cs_dialog)); - priv->popped = FALSE; -} - -/* Popup a color selector dialog on hardkey Select press. - * FIXME This is a bit hacky, should work without thi. Check. */ -static gboolean -hildon_color_button_key_pressed (GtkWidget *button, - GdkEventKey *event, - gpointer data) -{ - g_return_val_if_fail (HILDON_IS_COLOR_BUTTON (button), FALSE); - - if (event->keyval == HILDON_HARDKEY_SELECT) - { - hildon_color_button_clicked (GTK_BUTTON (button)); - return TRUE; - } - - return FALSE; -} - -static void -hildon_color_button_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonColorButton *cb = HILDON_COLOR_BUTTON (object); - HildonColorButtonPrivate *priv = HILDON_COLOR_BUTTON_GET_PRIVATE (cb); - g_assert (priv); - - switch (param_id) - { - - case PROP_COLOR: - priv->color = *(GdkColor *) g_value_get_boxed (value); - gtk_widget_queue_draw (GTK_WIDGET (cb)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -hildon_color_button_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - HildonColorButton *cb = HILDON_COLOR_BUTTON (object); - HildonColorButtonPrivate *priv = HILDON_COLOR_BUTTON_GET_PRIVATE (cb); - g_assert (priv); - - switch (param_id) - { - - case PROP_COLOR: - g_value_set_boxed (value, &priv->color); - break; - - case PROP_POPUP_SHOWN: - g_value_set_boolean (value, priv->popped); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -/** - * hildon_color_button_new: - * - * Creates a new color button. This returns a widget in the form of a - * small button containing a swatch representing the selected color. - * When the button is clicked, a color-selection dialog will open, - * allowing the user to select a color. The swatch will be updated to - * reflect the new color when the user finishes. - * - * Returns: a new color button - */ -GtkWidget* -hildon_color_button_new (void) -{ - return g_object_new (HILDON_TYPE_COLOR_BUTTON, NULL); -} - -/** - * hildon_color_button_new_with_color: - * @color: a #GdkColor for the initial color - * - * Creates a new color button with @color as the initial color. - * - * Returns: a new color button - */ -GtkWidget* -hildon_color_button_new_with_color (const GdkColor *color) -{ - return g_object_new (HILDON_TYPE_COLOR_BUTTON, "color", color, NULL); -} - -/** - * hildon_color_button_set_color: - * @button: a #HildonColorButton - * @color: a color to be set - * - * Sets the color selected by the button. - */ -void -hildon_color_button_set_color (HildonColorButton *button, - GdkColor *color) -{ - g_return_if_fail (HILDON_IS_COLOR_BUTTON (button)); - - g_object_set (G_OBJECT (button), "color", color, NULL); -} - -/** - * hildon_color_button_get_popup_shown - * @button: a #HildonColorButton - * - * This function checks if the color button has the color - * selection dialog currently popped-up. - * - * Returns: TRUE if the dialog is popped-up (visible to user). - * - */ -gboolean -hildon_color_button_get_popup_shown (HildonColorButton *button) -{ - HildonColorButtonPrivate *priv = NULL; - g_return_val_if_fail (HILDON_IS_COLOR_BUTTON (button), FALSE); - - priv = HILDON_COLOR_BUTTON_GET_PRIVATE (button); - g_assert (priv); - - return priv->popped; -} - -/** - * hildon_color_button_popdown - * @button: a #HildonColorButton - * - * If the color selection dialog is currently popped-up (visible) - * it will be popped-down (hidden). - * - */ -void -hildon_color_button_popdown (HildonColorButton *button) -{ - HildonColorButtonPrivate *priv = NULL; - g_return_if_fail (HILDON_IS_COLOR_BUTTON (button)); - - priv = HILDON_COLOR_BUTTON_GET_PRIVATE (button); - g_assert (priv); - - if (priv->popped && priv->dialog) { - gtk_dialog_response (GTK_DIALOG (priv->dialog), GTK_RESPONSE_CANCEL); - } -} - -/** - * hildon_color_button_get_color: - * @button: a #HildonColorButton - * @color: a color #GdkColor to be fillled with the current color - * - */ -void -hildon_color_button_get_color (HildonColorButton *button, - GdkColor *color) -{ - HildonColorButtonPrivate *priv = NULL; - g_return_if_fail (HILDON_IS_COLOR_BUTTON (button)); - g_return_if_fail (color != NULL); - - priv = HILDON_COLOR_BUTTON_GET_PRIVATE (button); - g_assert (priv); - - color->red = priv->color.red; - color->green = priv->color.green; - color->blue = priv->color.blue; - color->pixel = priv->color.pixel; -} - diff --git a/hildon/hildon-color-button.h b/hildon/hildon-color-button.h deleted file mode 100644 index cd131ea..0000000 --- a/hildon/hildon-color-button.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_COLOR_BUTTON_H__ -#define __HILDON_COLOR_BUTTON_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_COLOR_BUTTON \ - (hildon_color_button_get_type ()) - -#define HILDON_COLOR_BUTTON(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - HILDON_TYPE_COLOR_BUTTON, HildonColorButton)) - -#define HILDON_COLOR_BUTTON_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - GTK_TYPE_COLOR_BUTTON, HildonColorButtonClass)) - -#define HILDON_IS_COLOR_BUTTON(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - HILDON_TYPE_COLOR_BUTTON)) - -#define HILDON_IS_COLOR_BUTTON_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_COLOR_BUTTON)) - -#define HILDON_COLOR_BUTTON_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - HILDON_TYPE_COLOR_BUTTON, HildonColorButtonClass)) - -typedef struct _HildonColorButton HildonColorButton; - -typedef struct _HildonColorButtonClass HildonColorButtonClass; - -struct _HildonColorButton -{ - GtkButton parent; -}; - -struct _HildonColorButtonClass -{ - GtkButtonClass parent_class; -}; - -GType G_GNUC_CONST -hildon_color_button_get_type (void); - -GtkWidget* -hildon_color_button_new (void); - -GtkWidget* -hildon_color_button_new_with_color (const GdkColor *color); - -void -hildon_color_button_get_color (HildonColorButton *button, - GdkColor *color); - -void -hildon_color_button_set_color (HildonColorButton *button, - GdkColor *color); - -gboolean -hildon_color_button_get_popup_shown (HildonColorButton *button); - -void -hildon_color_button_popdown (HildonColorButton *button); - -G_END_DECLS - -#endif /* __HILDON_COLOR_BUTTON_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-color-chooser-dialog-private.h b/hildon/hildon-color-chooser-dialog-private.h deleted file mode 100644 index 4ebf42f..0000000 --- a/hildon/hildon-color-chooser-dialog-private.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Kuisma Salonen <kuisma.salonen@nokia.com> - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_COLOR_CHOOSER_DIALOG_PRIVATE_H__ -#define __HILDON_COLOR_CHOOSER_DIALOG_PRIVATE_H__ - -#include <gconf/gconf-client.h> - -typedef struct _HildonColorChooserDialogPrivate HildonColorChooserDialogPrivate; - -#define HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\ - HILDON_TYPE_COLOR_CHOOSER_DIALOG, HildonColorChooserDialogPrivate)); - -typedef struct -{ - GtkBorder radio_sizes; - GtkBorder cont_sizes; - GtkBorder num_buttons; - GtkBorder last_num_buttons; - - GdkColor default_color; -} HildonColorChooserStyleInfo; - -struct _HildonColorChooserDialogPrivate -{ - GtkWidget *hbox; - GtkWidget *vbox; - - GtkWidget *align_custom, *align_defined; - GtkWidget *area_custom, *area_defined; - GtkWidget *separator; - - GtkWidget *chooser; - - GdkColor *colors_custom, *colors_defined; - GdkColor color; - GdkGC **gc_array; - - gint selected; - - HildonColorChooserStyleInfo style_info; - - gint has_style; - - GdkColor pending_color; - - GConfClient *gconf_client; -}; - -#endif /* __HILDON_COLOR_CHOOSER_DIALOG_PRIVATE_H__ */ diff --git a/hildon/hildon-color-chooser-dialog.c b/hildon/hildon-color-chooser-dialog.c deleted file mode 100644 index 2b03461..0000000 --- a/hildon/hildon-color-chooser-dialog.c +++ /dev/null @@ -1,1149 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Kuisma Salonen <kuisma.salonen@nokia.com> - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-color-chooser-dialog - * @short_description: A dialog used to select a color from HSV colorspace. - * @see_also: #HildonColorButton - * - * HildonColorChooserDialog enables the user to - * select an arbitrary color from a HSV colorspace. - * The color is stored in one of the predefined color - * slots and can be reselected later on. - * - * Additionally the user can choose one of the standard "factory" - * colors. - * - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <memory.h> -#include <string.h> -#include <libintl.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-color-chooser-dialog.h" -#include "hildon-color-chooser.h" -#include "hildon-defines.h" -#include "hildon-banner.h" -#include "hildon-stock.h" -#include "hildon-color-chooser-dialog-private.h" - -#define _(String) dgettext("hildon-libs", String) - -static HildonColorChooserDialogClass* parent_class = NULL; - -/* darkened EGA palette to be used as predefined colors if style doesn't - define anything else (darker colors are darkened 0x8000 -> 0x6666) */ -static GdkColor hardcoded_colors[16] = {{0, 0x0000, 0x0000, 0x0000}, - {0, 0x6666, 0x6666, 0x6666}, - {0, 0x6666, 0x0000, 0x0000}, - {0, 0x0000, 0x6666, 0x0000}, - {0, 0x0000, 0x0000, 0x6666}, - {0, 0x6666, 0x6666, 0x0000}, - {0, 0x6666, 0x0000, 0x6666}, - {0, 0x0000, 0x6666, 0x6666}, - {0, 0xffff, 0xffff, 0xffff}, - {0, 0xc000, 0xc000, 0xc000}, - {0, 0xffff, 0x0000, 0x0000}, - {0, 0x0000, 0xffff, 0x0000}, - {0, 0x0000, 0x0000, 0xffff}, - {0, 0xffff, 0xffff, 0x0000}, - {0, 0xffff, 0x0000, 0xffff}, - {0, 0x0000, 0xffff, 0xffff}}; - -static void -hildon_color_chooser_dialog_init (HildonColorChooserDialog *object); - -static void -hildon_color_chooser_dialog_class_init (HildonColorChooserDialogClass *klass); - -static void -hildon_color_chooser_dialog_size_request (GtkWidget *widget, - GtkRequisition *req); - -static void -hildon_color_chooser_dialog_size_allocate (GtkWidget *widget, - GtkAllocation *alloc); - -static void -hildon_color_chooser_dialog_realize (GtkWidget *widget); - -static void -hildon_color_chooser_dialog_unrealize (GtkWidget *widget); - -static void -hildon_color_chooser_dialog_style_set (GtkWidget *widget, - GtkStyle *previous_style); - -static void -hildon_color_chooser_dialog_show (GtkWidget *widget); - -static void -hildon_color_chooser_dialog_show_all (GtkWidget *widget); - -static gboolean -hildon_color_chooser_dialog_key_press_event (GtkWidget *widget, - GdkEventKey *event); - -static gboolean -hildon_color_chooser_dialog_key_release_event (GtkWidget *widget, - GdkEventKey *event); - -static void -hildon_color_chooser_dialog_destroy (GtkObject *object); - -static gboolean -hildon_color_chooser_dialog_area_expose (GtkWidget *widget, - GdkEventExpose *event, - gpointer data); - -static gboolean -hildon_color_chooser_dialog_area_button_press (GtkWidget *widget, - GdkEventButton *event, - gpointer data); - -static void -hildon_color_chooser_dialog_color_changed (HildonColorChooser *chooser, - gpointer data); - -static void -hildon_color_chooser_dialog_insensitive_press (GtkWidget *widget, - gpointer data); - -static void -hildon_color_chooser_dialog_refresh_style_info (HildonColorChooserDialog *dialog); - -static void -hildon_color_chooser_dialog_set_color_num (HildonColorChooserDialog *dialog, - gint num); - -static void -hildon_color_chooser_dialog_ascii_hex_to_color (gchar *s, - GdkColor *color); - -static void -hildon_color_chooser_dialog_color_to_ascii_hex (gchar *s, - GdkColor *color); - -GType G_GNUC_CONST -hildon_color_chooser_dialog_get_type (void) -{ - static GType dialog_type = 0; - - if (!dialog_type) { - static const GTypeInfo dialog_info = - { - sizeof (HildonColorChooserDialogClass), - NULL, - NULL, - (GClassInitFunc) hildon_color_chooser_dialog_class_init, - NULL, - NULL, - sizeof (HildonColorChooserDialog), - 0, - (GInstanceInitFunc) hildon_color_chooser_dialog_init, - NULL - }; - - dialog_type = g_type_register_static (GTK_TYPE_DIALOG, - "HildonColorChooserDialog", &dialog_info, 0); - } - - return dialog_type; -} - -static void -hildon_color_chooser_dialog_init (HildonColorChooserDialog *object) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (object); - - gtk_dialog_set_has_separator (GTK_DIALOG (object), FALSE); - gtk_window_set_title (GTK_WINDOW (object), _("ecdg_ti_colour_selector")); - - g_assert (priv); - - priv->hbox = gtk_hbox_new (FALSE, 0); - priv->vbox = gtk_vbox_new (FALSE, 0); - priv->chooser = hildon_color_chooser_new (); - - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->chooser, TRUE, TRUE, 0); - gtk_box_pack_end (GTK_BOX (priv->hbox), priv->vbox, FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (object)->vbox), priv->hbox, TRUE, TRUE, 0); - - - priv->align_custom = gtk_alignment_new (0.5, 1.0, 0.0, 0.0); - priv->align_defined = gtk_alignment_new (0.5, 1.0, 0.0, 0.0); - - priv->area_custom = gtk_drawing_area_new (); - priv->area_defined = gtk_drawing_area_new (); - - gtk_container_add (GTK_CONTAINER (priv->align_custom), priv->area_custom); - gtk_container_add (GTK_CONTAINER (priv->align_defined), priv->area_defined); - - priv->separator = gtk_hseparator_new (); - - gtk_box_pack_start (GTK_BOX (priv->vbox), priv->align_defined, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (priv->vbox), priv->separator, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (priv->vbox), priv->align_custom, FALSE, FALSE, 0); - - gtk_dialog_add_button (GTK_DIALOG (object), HILDON_STOCK_DONE, GTK_RESPONSE_OK); - gtk_dialog_set_default_response (GTK_DIALOG (object), GTK_RESPONSE_OK); - - g_signal_connect (G_OBJECT (priv->chooser), - "query-tooltip", G_CALLBACK (hildon_color_chooser_dialog_insensitive_press), object); - - g_signal_connect (G_OBJECT (priv->area_custom), - "expose-event", G_CALLBACK (hildon_color_chooser_dialog_area_expose), object); - - g_signal_connect (G_OBJECT (priv->area_defined), - "expose-event", G_CALLBACK (hildon_color_chooser_dialog_area_expose), object); - - g_signal_connect (G_OBJECT (priv->area_custom), - "button-press-event", G_CALLBACK (hildon_color_chooser_dialog_area_button_press), object); - - g_signal_connect (G_OBJECT (priv->area_defined), - "button-press-event", G_CALLBACK (hildon_color_chooser_dialog_area_button_press), object); - - g_signal_connect (G_OBJECT (priv->chooser), - "color-changed", G_CALLBACK (hildon_color_chooser_dialog_color_changed), object); - - gtk_widget_add_events (priv->area_custom, GDK_BUTTON_PRESS_MASK); - gtk_widget_add_events (priv->area_defined, GDK_BUTTON_PRESS_MASK); - - priv->selected = 0; - priv->gconf_client = gconf_client_get_default (); - - memset (&priv->style_info, 0, sizeof (HildonColorChooserStyleInfo)); - - priv->colors_custom = NULL; - priv->colors_defined = NULL; - priv->gc_array = NULL; - - priv->has_style = 0; -} - -static void -hildon_color_chooser_dialog_class_init (HildonColorChooserDialogClass *klass) -{ - GtkWidgetClass *widget_klass = GTK_WIDGET_CLASS (klass); - GtkObjectClass *object_klass = GTK_OBJECT_CLASS (klass); - gchar tmp[32]; - gint i; - - widget_klass->size_request = hildon_color_chooser_dialog_size_request; - widget_klass->size_allocate = hildon_color_chooser_dialog_size_allocate; - widget_klass->realize = hildon_color_chooser_dialog_realize; - widget_klass->unrealize = hildon_color_chooser_dialog_unrealize; - widget_klass->style_set = hildon_color_chooser_dialog_style_set; - widget_klass->show = hildon_color_chooser_dialog_show; - widget_klass->show_all = hildon_color_chooser_dialog_show_all; - widget_klass->key_press_event = hildon_color_chooser_dialog_key_press_event; - widget_klass->key_release_event = hildon_color_chooser_dialog_key_release_event; - - - object_klass->destroy = hildon_color_chooser_dialog_destroy; - - parent_class = g_type_class_peek_parent (klass); - - gtk_widget_class_install_style_property (widget_klass, - g_param_spec_boxed ("container_sizes", - "Container sizes", - "Container specific sizes", - GTK_TYPE_BORDER, - G_PARAM_READABLE)); - - gtk_widget_class_install_style_property (widget_klass, - g_param_spec_boxed ("radio_sizes", - "Color radio sizes", - "Color radio specific sizes", - GTK_TYPE_BORDER, - G_PARAM_READABLE)); - - gtk_widget_class_install_style_property (widget_klass, - g_param_spec_boxed ("num_buttons", - "Number of buttons", - "Number of color store buttons", - GTK_TYPE_BORDER, - G_PARAM_READABLE)); - - gtk_widget_class_install_style_property (widget_klass, - g_param_spec_boxed ("default_color", "Default color", - "Default color for nonpainted custom colors", - GDK_TYPE_COLOR, - G_PARAM_READABLE)); - - for (i = 0; i < 32; i++) { - memset (tmp, 0, 32); - g_snprintf (tmp, 32, "defined_color%d", i); - - gtk_widget_class_install_style_property (widget_klass, - g_param_spec_boxed (tmp, "Defined color", - "Pre-defined colors for the dialog", - GDK_TYPE_COLOR, - G_PARAM_READABLE)); - } - - g_type_class_add_private (object_klass, sizeof (HildonColorChooserDialogPrivate)); -} - -static void -hildon_color_chooser_dialog_size_request (GtkWidget *widget, - GtkRequisition *req) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (widget); - - g_assert (priv); - - gtk_container_set_border_width (GTK_CONTAINER (priv->hbox), priv->style_info.cont_sizes.left); - - gtk_box_set_spacing (GTK_BOX (priv->hbox), priv->style_info.cont_sizes.right); - gtk_box_set_spacing (GTK_BOX (priv->vbox), priv->style_info.cont_sizes.top); - gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (widget)->vbox), priv->style_info.cont_sizes.bottom); - - gtk_widget_set_size_request (priv->area_custom, - (priv->style_info.radio_sizes.left + - 2 * priv->style_info.radio_sizes.bottom) * - (priv->style_info.num_buttons.top) + - (priv->style_info.num_buttons.top-1) * - priv->style_info.radio_sizes.top, - (priv->style_info.radio_sizes.right + - 2 * priv->style_info.radio_sizes.bottom) * - (priv->style_info.num_buttons.bottom) + - (priv->style_info.num_buttons.bottom-1) * - priv->style_info.radio_sizes.top); - - gtk_widget_set_size_request (priv->area_defined, - (priv->style_info.radio_sizes.left + - 2 * priv->style_info.radio_sizes.bottom) * - (priv->style_info.num_buttons.left) + - (priv->style_info.num_buttons.left-1) * - priv->style_info.radio_sizes.top, - (priv->style_info.radio_sizes.right + - 2 * priv->style_info.radio_sizes.bottom) * - (priv->style_info.num_buttons.right) + - (priv->style_info.num_buttons.right-1) * - priv->style_info.radio_sizes.top); - - GTK_WIDGET_CLASS (parent_class)->size_request (widget, req); -} - -static void -hildon_color_chooser_dialog_size_allocate (GtkWidget *widget, - GtkAllocation *alloc) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (widget); - - GdkRectangle rect; - int i, tmp, tmp2; - - g_assert (priv); - - GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, alloc); - - if (GTK_WIDGET_REALIZED (widget)) { - tmp = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right); - tmp2 = (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - - for (i = 0; i < tmp; i++) { - rect.x = ((i % priv->style_info.num_buttons.left) * - (priv->style_info.radio_sizes.left + - priv->style_info.radio_sizes.top + - 2 * priv->style_info.radio_sizes.bottom)) + - priv->style_info.radio_sizes.bottom; - - rect.y = ((i / priv->style_info.num_buttons.left) * - (priv->style_info.radio_sizes.right + - priv->style_info.radio_sizes.top + - 2 * priv->style_info.radio_sizes.bottom)) + - priv->style_info.radio_sizes.bottom; - - rect.width = priv->style_info.radio_sizes.left; - rect.height = priv->style_info.radio_sizes.right; - - gdk_gc_set_clip_rectangle (priv->gc_array[i], &rect); - } - - for (i = 0; i < tmp2; i++) { - rect.x = ((i % priv->style_info.num_buttons.top) * - (priv->style_info.radio_sizes.left + - priv->style_info.radio_sizes.top + - 2 * priv->style_info.radio_sizes.bottom)) + - priv->style_info.radio_sizes.bottom; - - rect.y = ((i / priv->style_info.num_buttons.top) * - (priv->style_info.radio_sizes.right + - priv->style_info.radio_sizes.top + - 2 * priv->style_info.radio_sizes.bottom)) + priv->style_info.radio_sizes.bottom; - - rect.width = priv->style_info.radio_sizes.left; - rect.height = priv->style_info.radio_sizes.right; - - gdk_gc_set_clip_rectangle (priv->gc_array[i + tmp], &rect); - } - } -} - -static void -hildon_color_chooser_dialog_realize (GtkWidget *widget) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (widget); - - GdkRectangle rect; - int i, tmp, tmp2; - - g_assert (priv); - - GTK_WIDGET_CLASS(parent_class)->realize (widget); - - tmp = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right) + - (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - - for (i = 0; i < tmp; i++) { - priv->gc_array[i] = gdk_gc_new (widget->window); - } - - tmp = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right); - tmp2 = (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - - for (i = 0; i < tmp; i++) { - gdk_gc_set_rgb_fg_color (priv->gc_array[i], &priv->colors_defined[i]); - - rect.x = ((i % priv->style_info.num_buttons.left) * - (priv->style_info.radio_sizes.left + - priv->style_info.radio_sizes.top + - 2 * priv->style_info.radio_sizes.bottom)) + - priv->style_info.radio_sizes.bottom; - - rect.y = ((i / priv->style_info.num_buttons.left) * - (priv->style_info.radio_sizes.right + - priv->style_info.radio_sizes.top + - 2 * priv->style_info.radio_sizes.bottom)) + - priv->style_info.radio_sizes.bottom; - - rect.width = priv->style_info.radio_sizes.left; - rect.height = priv->style_info.radio_sizes.right; - - gdk_gc_set_clip_rectangle (priv->gc_array[i], &rect); - } - - for (i = 0; i < tmp2; i++) { - gdk_gc_set_rgb_fg_color (priv->gc_array[i + tmp], &priv->colors_custom[i]); - - rect.x = ((i % priv->style_info.num_buttons.top) * - (priv->style_info.radio_sizes.left + - priv->style_info.radio_sizes.top + - 2 * priv->style_info.radio_sizes.bottom)) + - priv->style_info.radio_sizes.bottom; - - rect.y = ((i / priv->style_info.num_buttons.top) * - (priv->style_info.radio_sizes.right + - priv->style_info.radio_sizes.top + - 2 * priv->style_info.radio_sizes.bottom)) + - priv->style_info.radio_sizes.bottom; - - rect.width = priv->style_info.radio_sizes.left; - rect.height = priv->style_info.radio_sizes.right; - - gdk_gc_set_clip_rectangle (priv->gc_array[i + tmp], &rect); - } -} - -static void -hildon_color_chooser_dialog_unrealize (GtkWidget *widget) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (widget); - - int i, tmp; - - tmp = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right) + - (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - - for (i = 0; i < tmp; i++) { - g_object_unref (priv->gc_array[i]); - priv->gc_array[i] = NULL; - } - - GTK_WIDGET_CLASS (parent_class)->unrealize (widget); -} - -static void -hildon_color_chooser_dialog_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - HildonColorChooserDialog *dialog = HILDON_COLOR_CHOOSER_DIALOG (widget); - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (widget); - - GdkColor *tmpcolor; - gchar tmp[32], key[128], *val; - int i, tmpn, setcolor = 0; - - g_assert (priv); - - if (! priv->has_style) - setcolor = 1; - - priv->has_style = 1; - - gtk_widget_style_get (widget, "default_color", &tmpcolor, NULL); - - if (tmpcolor) { - priv->style_info.default_color = *tmpcolor; - gdk_color_free (tmpcolor); - } else { - priv->style_info.default_color.red = 0x0000; - priv->style_info.default_color.green = 0x0000; - priv->style_info.default_color.blue = 0x0000; - priv->style_info.default_color.pixel = 0x00000000; - } - - hildon_color_chooser_dialog_refresh_style_info (dialog); - - if (memcmp (&priv->style_info.num_buttons, &priv->style_info.last_num_buttons, sizeof (GtkBorder))) { - if (priv->colors_custom) { - g_free (priv->colors_custom); - } if (priv->colors_defined) { - g_free (priv->colors_defined); - } if (priv->gc_array) { - if (GTK_WIDGET_REALIZED (widget)) { - tmpn = (priv->style_info.last_num_buttons.left * priv->style_info.last_num_buttons.right) + - (priv->style_info.last_num_buttons.top * priv->style_info.last_num_buttons.bottom); - - for (i = 0; i < tmpn; i++) { - g_object_unref (priv->gc_array[i]); - priv->gc_array[i] = NULL; - } - } - - g_free (priv->gc_array); - } - - priv->colors_custom = (GdkColor *) - g_malloc0 (sizeof (GdkColor) * (priv->style_info.num_buttons.top * - priv->style_info.num_buttons.bottom)); - - priv->colors_defined = (GdkColor *) - g_malloc0 (sizeof(GdkColor) * (priv->style_info.num_buttons.left * - priv->style_info.num_buttons.right)); - - tmpn = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right) + - (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - - priv->gc_array = (GdkGC **) g_malloc0 (sizeof (GdkGC *) * tmpn); - if (GTK_WIDGET_REALIZED (widget)) { - for (i = 0; i < tmpn; i++) { - priv->gc_array[i] = gdk_gc_new (widget->window); - } - } - - if (priv->gconf_client) { - - for (i = 0; i < (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); i++) { - memset (key, 0, 128); - /* FIXME Extremally bad hardcoding */ - g_snprintf (key, 128, "/system/osso/af/color_chooser/custom_color%d", i); - val = gconf_client_get_string (priv->gconf_client, key, NULL); - - if (val) { - hildon_color_chooser_dialog_ascii_hex_to_color (val, &priv->colors_custom[i]); - g_free (val); - } else { - priv->colors_custom[i] = priv->style_info.default_color; - } - } - } else { - for (i = 0; i < (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); i++) { - priv->colors_custom[i] = priv->style_info.default_color; - } - } - } - - tmpn = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right); - - hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (priv->chooser), - (priv->selected < tmpn) ? - &priv->colors_defined[priv->selected] : - &priv->colors_custom[priv->selected - tmpn]); - - for (i = 0; i < (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right); i++) { - memset (tmp, 0, 32); - g_snprintf (tmp, 32, "defined_color%d", i); - - gtk_widget_style_get (widget, tmp, &tmpcolor, NULL); - - if (tmpcolor) { - priv->colors_defined[i] = *tmpcolor; - gdk_color_free (tmpcolor); - } else { - if(i < 16) { - priv->colors_defined[i] = hardcoded_colors[i]; - } else { /* fallback to prevent segfault */ - priv->colors_defined[i].red = 0x0000; - priv->colors_defined[i].green = 0x0000; - priv->colors_defined[i].blue = 0x0000; - priv->colors_defined[i].pixel = 0x00000000; - } - } - } - - if (GTK_WIDGET_REALIZED (widget)) { - for (i = 0; i < (priv->style_info.num_buttons.left * - priv->style_info.num_buttons.right); i++) { - gdk_gc_set_rgb_fg_color (priv->gc_array[i], &priv->colors_defined[i]); - } - } - - if (setcolor) - hildon_color_chooser_dialog_set_color (HILDON_COLOR_CHOOSER_DIALOG (dialog), - &priv->pending_color); - - gtk_widget_queue_resize (widget); - - GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style); -} - -static void -hildon_color_chooser_dialog_show (GtkWidget *widget) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (widget); - - g_assert (priv); - - gtk_widget_show (priv->hbox); - gtk_widget_show (priv->vbox); - - gtk_widget_show (priv->chooser); - - gtk_widget_show (priv->align_custom); - gtk_widget_show (priv->align_defined); - - gtk_widget_show (priv->separator); - - gtk_widget_show (priv->area_custom); - gtk_widget_show (priv->area_defined); - - GTK_WIDGET_CLASS (parent_class)->show (widget); -} - -/* FIXME WTF this function is even needed here? */ -static void -hildon_color_chooser_dialog_show_all (GtkWidget *widget) -{ - hildon_color_chooser_dialog_show (widget); -} - -static gboolean -hildon_color_chooser_dialog_key_press_event (GtkWidget *widget, - GdkEventKey *event) -{ - HildonColorChooserDialog *dialog = HILDON_COLOR_CHOOSER_DIALOG (widget); - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (widget); - int tmp, tot, sel; - - g_assert (priv); - - if (event->keyval == HILDON_HARDKEY_UP || event->keyval == HILDON_HARDKEY_DOWN || - event->keyval == HILDON_HARDKEY_LEFT || event->keyval == HILDON_HARDKEY_RIGHT) { - tmp = (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - tot = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right) + tmp; - - switch (event->keyval) { - - case HILDON_HARDKEY_UP: - if(priv->selected >= priv->style_info.num_buttons.top) { - if(priv->selected - priv->style_info.num_buttons.left >= tmp) { - sel = priv->selected - priv->style_info.num_buttons.left; - } else { - sel = priv->selected - priv->style_info.num_buttons.top; - } - - hildon_color_chooser_dialog_set_color_num (dialog, sel); - } - break; - - case HILDON_HARDKEY_DOWN: - if(priv->selected < tot - priv->style_info.num_buttons.left) { - if(priv->selected < tmp) { - sel = priv->selected + priv->style_info.num_buttons.top; - } else { - sel = priv->selected + priv->style_info.num_buttons.left; - } - - hildon_color_chooser_dialog_set_color_num (dialog, sel); - } - break; - - case HILDON_HARDKEY_LEFT: - if ((priv->selected < tmp ? - (priv->selected % priv->style_info.num_buttons.top) : - ((priv->selected - tmp) % priv->style_info.num_buttons.left)) > 0) { - sel = priv->selected - 1; - - hildon_color_chooser_dialog_set_color_num (dialog, sel); - } - break; - - case HILDON_HARDKEY_RIGHT: - if ((priv->selected < tmp) ? - (priv->selected % priv->style_info.num_buttons.top < priv->style_info.num_buttons.top - 1) : - ((priv->selected - tmp) % priv->style_info.num_buttons.left < priv->style_info.num_buttons.left - 1)) { - sel = priv->selected + 1; - - hildon_color_chooser_dialog_set_color_num (dialog, sel); - } - break; - - default: - break; - } - - return FALSE; - } - - return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event); -} - -static gboolean -hildon_color_chooser_dialog_key_release_event (GtkWidget *widget, - GdkEventKey *event) -{ - if (event->keyval == HILDON_HARDKEY_UP || - event->keyval == HILDON_HARDKEY_DOWN || - event->keyval == HILDON_HARDKEY_LEFT || - event->keyval == HILDON_HARDKEY_RIGHT) - { - return FALSE; - } - - return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event); -} - -static void -hildon_color_chooser_dialog_destroy (GtkObject *object) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (object); - - gchar key[128], color[13]; - int i, tmp; - - g_assert (priv); - - if (priv->gconf_client) { - memset (color, 0, 13); - - tmp = (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - - for (i = 0; i < tmp; i++) { - memset (key, 0, 128); - /* FIXME Extremally bad hardcoding */ - g_snprintf (key, 128, "/system/osso/af/color_chooser/custom_color%d", i); - hildon_color_chooser_dialog_color_to_ascii_hex (color, &priv->colors_custom[i]); - gconf_client_set_string (priv->gconf_client, key, color, NULL); - } - - g_object_unref (priv->gconf_client); - priv->gconf_client = NULL; - } - - if (priv->gc_array) { - g_free (priv->gc_array); - priv->gc_array = NULL; - } if (priv->colors_defined) { - g_free (priv->colors_defined); - priv->colors_defined = NULL; - } if (priv->colors_custom) { - g_free (priv->colors_custom); - priv->colors_custom = NULL; - } - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -/** - * hildon_color_chooser_dialog_set_color: - * @dialog: a #HildonColorChooserDialog - * @color: a color to set on the #HildonColorChooserDialog - * - * Sets the dialog to point at the given color. It'll first try to - * search the palette of the existing colors to match the passed color. - * If the color is not found in the pallette, the color in the currently - * selected box will be modified. - * - */ -void -hildon_color_chooser_dialog_set_color (HildonColorChooserDialog *dialog, - GdkColor *color) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (dialog); - - int i, found = -1, tmp, tmp2; - - g_assert (priv); - - if (! priv->has_style) { - priv->pending_color = *color; - return; - } - - tmp = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right); - tmp2 = (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - - for (i = 0; i < tmp; i++) { - if (priv->colors_defined[i].red == color->red && - priv->colors_defined[i].green == color->green && - priv->colors_defined[i].blue == color->blue) { - found = i; - break; - } - } - - if (found == -1) { - for (i = 0; i < tmp2; i++) { - if (priv->colors_custom[i].red == color->red && - priv->colors_custom[i].green == color->green && - priv->colors_custom[i].blue == color->blue) { - found = i + tmp; - break; - } - } - } - - if (found == -1) { - priv->colors_custom[tmp2-1] = *color; - if (GTK_WIDGET_REALIZED (GTK_WIDGET (dialog))) { - gdk_gc_set_rgb_fg_color (priv->gc_array[tmp2-1], color); - } - hildon_color_chooser_dialog_set_color_num (dialog, tmp2 - 1); - } else { - hildon_color_chooser_dialog_set_color_num (dialog, found); - } -} - -static gboolean -hildon_color_chooser_dialog_area_expose (GtkWidget *widget, - GdkEventExpose *event, - gpointer data) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (data); - - int i, num_selected, tot_w, tot_h, spacing, brd, x, y; - GdkGC **start_gc; - int tmp, w, h; - - g_assert (priv); - - tmp = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right); - - if (widget == priv->area_custom) { - num_selected = priv->selected - tmp; - start_gc = priv->gc_array + tmp; - tmp = (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - w = priv->style_info.num_buttons.top; - h = priv->style_info.num_buttons.bottom; - } else { /* widget == dialog->area_defined */ - num_selected = priv->selected; - start_gc = priv->gc_array; - w = priv->style_info.num_buttons.left; - h = priv->style_info.num_buttons.right; - } - - spacing = priv->style_info.radio_sizes.top; - brd = priv->style_info.radio_sizes.bottom; - tot_w = priv->style_info.radio_sizes.left + 2 * brd; - tot_h = priv->style_info.radio_sizes.right + 2 * brd; - - for (i = 0; i < tmp; i++) { - x = ((i % w) * (tot_w + spacing)); - y = ((i / w) * (tot_h + spacing)); - - gdk_draw_rectangle (widget->window, - (i == num_selected) ? widget->style->bg_gc[GTK_STATE_SELECTED] : widget->style->bg_gc[GTK_STATE_NORMAL], - TRUE, - (i == num_selected) ? x : x + 2, - (i == num_selected) ? y : y + 2, - (i == num_selected) ? tot_w : tot_w - 4, - (i == num_selected) ? tot_h : tot_h - 4); - - gdk_draw_rectangle(widget->window, - (i == num_selected) ? widget->style->bg_gc[GTK_STATE_NORMAL] : widget->style->white_gc, - TRUE, - x + 3, - y + 3, - tot_w - 6, - tot_h - 6); - - gdk_draw_rectangle(widget->window, - start_gc [i], - TRUE, - x + 3 + 1, - y + 3 + 1, - tot_w - 6 - 2, - tot_h - 6 - 2); - } - - return FALSE; -} - -static gboolean -hildon_color_chooser_dialog_area_button_press (GtkWidget *widget, - GdkEventButton *event, - gpointer data) -{ - HildonColorChooserDialog *dialog = HILDON_COLOR_CHOOSER_DIALOG (data); - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (data); - - int i, hskip, vskip, brd, selection = -1; - int x, y, tmp, tmp2, w; - - g_assert (priv); - - x = event->x; - y = event->y; - - brd = priv->style_info.radio_sizes.bottom; - hskip = priv->style_info.radio_sizes.left + - priv->style_info.radio_sizes.top + 2 * brd; - vskip = priv->style_info.radio_sizes.right + - priv->style_info.radio_sizes.top + 2 * brd; - - tmp = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right); - tmp2 = (priv->style_info.num_buttons.top * priv->style_info.num_buttons.bottom); - - if (widget == priv->area_defined) { - w = priv->style_info.num_buttons.left; - - for (i = 0; i < tmp; i++) { - if (x >= hskip * (i % w) + brd && x < hskip * (i % w) + brd + priv->style_info.radio_sizes.left && - y >= vskip * (i / w) + brd && y < hskip * (i / w) + brd + priv->style_info.radio_sizes.right) { - selection = i; - break; - } - } - } else { - w = priv->style_info.num_buttons.top; - for (i = 0; i < tmp2; i++) { - if (x >= hskip * (i % w) + brd && x < hskip * (i % w) + brd + priv->style_info.radio_sizes.left && - y >= vskip * (i / w) + brd && y < hskip * (i / w) + brd + priv->style_info.radio_sizes.right) { - selection = i + tmp; - break; - } - } - } - - if (selection != -1) { - hildon_color_chooser_dialog_set_color_num (dialog, selection); - } - - return FALSE; -} - -static void -hildon_color_chooser_dialog_color_changed (HildonColorChooser *chooser, - gpointer data) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (data); - char key[128], color_str[13]; - int tmp; - GdkColor color; - - g_assert (priv); - - hildon_color_chooser_get_color (chooser, &color); - - tmp = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right); - - if (priv->selected >= tmp) { - priv->colors_custom[priv->selected - tmp] = color; - - gdk_gc_set_rgb_fg_color (priv->gc_array[priv->selected], &priv->colors_custom[priv->selected - tmp]); - gtk_widget_queue_draw (priv->area_custom); - - if (priv->gconf_client) { - memset (key, 0, 128); - memset (color_str, 0, 13); - /* FIXME Ugly hardcoded stuff! */ - g_snprintf (key, 128, "/system/osso/af/color_chooser/custom_color%d", priv->selected - tmp); - hildon_color_chooser_dialog_color_to_ascii_hex (color_str, &priv->colors_custom[priv->selected - tmp]); - gconf_client_set_string (priv->gconf_client, key, color_str, NULL); - } - } -} - -static void -hildon_color_chooser_dialog_insensitive_press (GtkWidget *widget, - gpointer data) -{ - hildon_banner_show_information (widget, NULL, _("ecdg_ib_colour_selector_predefined")); -} - -/* function has size defaults */ -static void -hildon_color_chooser_dialog_refresh_style_info (HildonColorChooserDialog *dialog) -{ - GtkBorder *tmp1, *tmp2, *tmp3; - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (dialog); - - g_assert (priv); - - gtk_widget_style_get (GTK_WIDGET (dialog), "container_sizes", &tmp1, - "radio_sizes", &tmp2, "num_buttons", &tmp3, NULL); - - priv->style_info.last_num_buttons = priv->style_info.num_buttons; - - if (tmp1) { - priv->style_info.cont_sizes = *tmp1; - gtk_border_free (tmp1); - } else { - priv->style_info.cont_sizes.left = 0; - priv->style_info.cont_sizes.right = 8; - priv->style_info.cont_sizes.top = 4; - priv->style_info.cont_sizes.bottom = 0; - } - - if (tmp2) { - priv->style_info.radio_sizes = *tmp2; - gtk_border_free (tmp2); - } else { - priv->style_info.radio_sizes.left = 16; - priv->style_info.radio_sizes.right = 16; - priv->style_info.radio_sizes.top = 4; - priv->style_info.radio_sizes.bottom = 2; - } - - if (tmp3) { - priv->style_info.num_buttons = *tmp3; - gtk_border_free (tmp3); - } else { - priv->style_info.num_buttons.left = 8; - priv->style_info.num_buttons.right = 2; - priv->style_info.num_buttons.top = 8; - priv->style_info.num_buttons.bottom = 2; - } -} - -static void -hildon_color_chooser_dialog_set_color_num (HildonColorChooserDialog *dialog, - gint num) -{ - HildonColorChooserDialogPrivate *priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (dialog); - - int tmp; - - g_assert (priv); - - tmp = (priv->style_info.num_buttons.left * priv->style_info.num_buttons.right); - - if (num < tmp) { - gtk_widget_set_sensitive (priv->chooser, FALSE); - } else { - gtk_widget_set_sensitive (priv->chooser, TRUE); - } - - priv->selected = num; - - gtk_widget_queue_draw (priv->area_custom); - gtk_widget_queue_draw (priv->area_defined); - - priv->color = (num < tmp) ? priv->colors_defined[num] : priv->colors_custom[num - tmp]; - - hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (priv->chooser), - (num < tmp) ? &priv->colors_defined[num] : &priv->colors_custom[num - tmp]); -} - -static void -hildon_color_chooser_dialog_ascii_hex_to_color (gchar *s, - GdkColor *color) -{ - int vals[12], i; - - for (i = 0; i < 12; i++) { - if (s[i] >= '0' && s[i] <= '9') { - vals[i] = s[i] - 0x30; - } else if (s[i] >= 'a' && s[i] <= 'f') { - vals[i] = s[i] - 0x57; - } else { - vals[i] = 0; - } - } - - color->red = (vals[0] << 12) | (vals[1] << 8) | (vals[2 ] << 4) | (vals[3 ]); - color->green = (vals[4] << 12) | (vals[5] << 8) | (vals[6 ] << 4) | (vals[7 ]); - color->blue = (vals[8] << 12) | (vals[9] << 8) | (vals[10] << 4) | (vals[11]); -} - -static void -hildon_color_chooser_dialog_color_to_ascii_hex (gchar *s, - GdkColor *color) -{ - g_snprintf (s, 13, "%x%x%x%x%x%x%x%x%x%x%x%x", - (color->red >> 12) & 0xf, (color->red >> 8) & 0xf, - (color->red >> 4) & 0xf, (color->red ) & 0xf, - (color->green >> 12) & 0xf, (color->green >> 8) & 0xf, - (color->green >> 4) & 0xf, (color->green ) & 0xf, - (color->blue >> 12) & 0xf, (color->blue >> 8) & 0xf, - (color->blue >> 4) & 0xf, (color->blue ) & 0xf); -} - -/** - * hildon_color_chooser_dialog_new: - * - * Creates a new color chooser dialog. - * - * Returns: a new color chooser dialog. - */ -GtkWidget* -hildon_color_chooser_dialog_new (void) -{ - return g_object_new (HILDON_TYPE_COLOR_CHOOSER_DIALOG, NULL); -} - -/** - * hildon_color_chooser_dialog_get_color: - * @dialog: a #HildonColorChooserDialog - * @color: a color structure to fill with the currently selected color - * - * Retrives the currently selected color in the color chooser dialog. - * - */ -void -hildon_color_chooser_dialog_get_color (HildonColorChooserDialog *dialog, - GdkColor *color) -{ - /* FIXME Should return pending color? */ - HildonColorChooserDialogPrivate *priv; - - g_return_if_fail (HILDON_IS_COLOR_CHOOSER_DIALOG (dialog)); - priv = HILDON_COLOR_CHOOSER_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - hildon_color_chooser_get_color (HILDON_COLOR_CHOOSER (priv->chooser), color); -} - diff --git a/hildon/hildon-color-chooser-dialog.h b/hildon/hildon-color-chooser-dialog.h deleted file mode 100644 index cb51d00..0000000 --- a/hildon/hildon-color-chooser-dialog.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Kuisma Salonen <kuisma.salonen@nokia.com> - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_COLOR_CHOOSER_DIALOG_H__ -#define __HILDON_COLOR_CHOOSER_DIALOG_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_COLOR_CHOOSER_DIALOG \ - (hildon_color_chooser_dialog_get_type()) - -#define HILDON_COLOR_CHOOSER_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - HILDON_TYPE_COLOR_CHOOSER_DIALOG, \ - HildonColorChooserDialog)) - -#define HILDON_COLOR_CHOOSER_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - HILDON_TYPE_COLOR_CHOOSER_DIALOG, \ - HildonColorChooserDialogClass)) - -#define HILDON_IS_COLOR_CHOOSER_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - HILDON_TYPE_COLOR_CHOOSER_DIALOG)) - -typedef struct _HildonColorChooserDialog HildonColorChooserDialog; - -typedef struct _HildonColorChooserDialogClass HildonColorChooserDialogClass; - -struct _HildonColorChooserDialog -{ - GtkDialog parent; -}; - -struct _HildonColorChooserDialogClass -{ - GtkDialogClass parent_class; -}; - -GType G_GNUC_CONST -hildon_color_chooser_dialog_get_type (void); - -GtkWidget* -hildon_color_chooser_dialog_new (void); - -void -hildon_color_chooser_dialog_set_color (HildonColorChooserDialog *dialog, - GdkColor *color); - -void -hildon_color_chooser_dialog_get_color (HildonColorChooserDialog *dialog, - GdkColor *color); - -G_END_DECLS - -#endif /* __HILDON_COLOR_CHOOSER_DIALOG_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-color-chooser-private.h b/hildon/hildon-color-chooser-private.h deleted file mode 100644 index 80f04fb..0000000 --- a/hildon/hildon-color-chooser-private.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Kuisma Salonen <kuisma.salonen@nokia.com> - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_COLOR_CHOOSER_PRIVATE_H__ -#define __HILDON_COLOR_CHOOSER_PRIVATE_H__ - -typedef struct _HildonColorChooserPrivate HildonColorChooserPrivate; - -#define HILDON_COLOR_CHOOSER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\ - HILDON_TYPE_COLOR_CHOOSER, HildonColorChooserPrivate)); - -struct _HildonColorChooserPrivate -{ - HildonColorChooser parent; - - GtkAllocation hba; - GtkAllocation spa; - - unsigned short currhue; - unsigned short currsat; - unsigned short currval; - - int mousestate; - gboolean mousein; - - GdkWindow *event_window; - - GdkPixbuf *dimmed_plane; - GdkPixbuf *dimmed_bar; - - struct { - unsigned short last_expose_hue; - - GTimeVal last_expose_time; - - int expose_queued; - } expose_info; -}; - -#endif /* __HILDON_COLOR_CHOOSER_H__ */ diff --git a/hildon/hildon-color-chooser.c b/hildon/hildon-color-chooser.c deleted file mode 100644 index 1dd0293..0000000 --- a/hildon/hildon-color-chooser.c +++ /dev/null @@ -1,1372 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Kuisma Salonen <kuisma.salonen@nokia.com> - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-color-chooser - * @short_description: A widget used to select a color from an HSV colorspace. - * @see_also: #HildonColorChooserDialog - * - * HildonColorChooser is a widget that displays an HSV colorspace. - * The user can manipulate the colorspace and easily select and shade of any color - * he wants. - * - * Normally you should not need to use this widget directly. Using #HildonColorButton or - * #HildonColorChooserDialog is much more handy. - * - */ - -#undef HILDON_DISABLE_DEPRECATED - -#include "hildon-color-chooser.h" -#include "hildon-color-chooser-private.h" - -static GtkWidgetClass* parent_class = NULL; - -/* "crosshair" is hardcoded for now */ -static gchar crosshair[64] = { 0, 0, 0, 2, 2, 0, 0, 0, - 0, 2, 2, 3, 3, 2, 2, 0, - 0, 2, 3, 0, 0, 3, 2, 0, - 2, 3, 0, 0, 0, 0, 3, 2, - 2, 3, 0, 0, 0, 0, 3, 2, - 0, 2, 3, 0, 0, 3, 2, 0, - 0, 2, 2, 3, 3, 2, 2, 0, - 0, 0, 0, 2, 2, 0, 0, 0}; - -static void -hildon_color_chooser_init (HildonColorChooser *self); - -static void -hildon_color_chooser_class_init (HildonColorChooserClass *klass); - -static void -hildon_color_chooser_dispose (HildonColorChooser *self); - -static void -hildon_color_chooser_size_request (GtkWidget *widget, - GtkRequisition *req); - -static void -hildon_color_chooser_size_allocate (GtkWidget *widget, - GtkAllocation *alloc); - -static void -hildon_color_chooser_realize (GtkWidget *widget); - -static void -hildon_color_chooser_unrealize (GtkWidget *widget); - -static void -hildon_color_chooser_map (GtkWidget *widget); - -static void -hildon_color_chooser_unmap (GtkWidget *widget); - -static gboolean -hildon_color_chooser_expose (GtkWidget *widget, - GdkEventExpose *event); - -static gboolean -hildon_color_chooser_button_press (GtkWidget *widget, - GdkEventButton *event); - -static gboolean -hildon_color_chooser_button_release (GtkWidget *widget, - GdkEventButton *event); - -static gboolean -hildon_color_chooser_pointer_motion (GtkWidget *widget, - GdkEventMotion *event); - -static void -get_border (GtkWidget *w, - char *name, - GtkBorder *b); - -static void -init_borders (GtkWidget *w, - GtkBorder *inner, - GtkBorder *outer); - -inline void -inline_clip_to_alloc (void *s, - GtkAllocation *a); - -inline void -inline_sub_times (GTimeVal *result, - GTimeVal *greater, - GTimeVal *lesser); - -inline void -inline_limited_expose (HildonColorChooser *self); - -inline void -inline_draw_hue_bar (GtkWidget *widget, - int x, - int y, - int w, - int h, - int sy, - int sh); - -inline void -inline_draw_hue_bar_dimmed (GtkWidget *widget, - int x, - int y, - int w, - int h, - int sy, - int sh); - -inline void -inline_draw_sv_plane (HildonColorChooser *self, - int x, - int y, - int w, - int h); - -inline void -inline_draw_sv_plane_dimmed (HildonColorChooser *self, - int x, - int y, - int w, - int h); - -inline void -inline_draw_crosshair (unsigned char *buf, - int x, - int y, - int w, - int h); - -inline void -inline_h2rgb (unsigned short hue, - unsigned long *rgb); - -static gboolean -hildon_color_chooser_expose_timer (gpointer data); - -static void -hildon_color_chooser_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_color_chooser_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -#define EXPOSE_INTERVAL 50000 - -#define FULL_COLOR8 0xff - -#define FULL_COLOR 0x00ffffff - -enum -{ - COLOR_CHANGED, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_COLOR -}; - -static guint color_chooser_signals [LAST_SIGNAL] = { 0 }; - -GType G_GNUC_CONST -hildon_color_chooser_get_type (void) -{ - static GType chooser_type = 0; - - if (!chooser_type) { - static const GTypeInfo chooser_info = - { - sizeof (HildonColorChooserClass), - NULL, - NULL, - (GClassInitFunc) hildon_color_chooser_class_init, - NULL, - NULL, - sizeof (HildonColorChooser), - 0, - (GInstanceInitFunc) hildon_color_chooser_init, - NULL - }; - - chooser_type = g_type_register_static (GTK_TYPE_WIDGET, - "HildonColorChooser", - &chooser_info, 0); - } - - return chooser_type; -} - -static void -hildon_color_chooser_init (HildonColorChooser *sel) -{ - - GTK_WIDGET_SET_FLAGS (sel, GTK_NO_WINDOW); - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (sel); - g_assert (priv); - - priv->currhue = 0; - priv->currsat = 0; - priv->currval = 0; - - priv->mousestate = 0; - priv->mousein = FALSE; - - g_get_current_time (&priv->expose_info.last_expose_time); - - priv->expose_info.last_expose_hue = priv->currhue; - priv->expose_info.expose_queued = 0; - - priv->dimmed_plane = NULL; - priv->dimmed_bar = NULL; -} - -static void -hildon_color_chooser_class_init (HildonColorChooserClass *klass) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - object_class->dispose = (gpointer) hildon_color_chooser_dispose; - object_class->get_property = hildon_color_chooser_get_property; - object_class->set_property = hildon_color_chooser_set_property; - - widget_class->size_request = hildon_color_chooser_size_request; - widget_class->size_allocate = hildon_color_chooser_size_allocate; - widget_class->realize = hildon_color_chooser_realize; - widget_class->unrealize = hildon_color_chooser_unrealize; - widget_class->map = hildon_color_chooser_map; - widget_class->unmap = hildon_color_chooser_unmap; - widget_class->expose_event = hildon_color_chooser_expose; - widget_class->button_press_event = hildon_color_chooser_button_press; - widget_class->button_release_event = hildon_color_chooser_button_release; - widget_class->motion_notify_event = hildon_color_chooser_pointer_motion; - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_boxed ("inner_size", - "Inner sizes", - "Sizes of SV plane, H bar and spacing", - GTK_TYPE_BORDER, - G_PARAM_READABLE)); - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_boxed ("outer_border", - "Outer border", - "The outer border for the chooser", - GTK_TYPE_BORDER, - G_PARAM_READABLE)); - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_boxed ("graphic_border", - "Graphical borders", - "Size of graphical border", - GTK_TYPE_BORDER, - G_PARAM_READABLE)); - - /** - * HildonColorChooser:color: - * - * The currently selected color. - */ - g_object_class_install_property (object_class, PROP_COLOR, - g_param_spec_boxed ("color", - "Current Color", - "The selected color", - GDK_TYPE_COLOR, - G_PARAM_READWRITE)); - - color_chooser_signals[COLOR_CHANGED] = g_signal_new("color-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonColorChooserClass, color_changed), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_type_class_add_private (klass, sizeof (HildonColorChooserPrivate)); -} - -static void -hildon_color_chooser_dispose (HildonColorChooser *sel) -{ - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (sel); - g_assert (priv); - - if (priv->dimmed_bar != NULL) { - g_object_unref (priv->dimmed_bar); - priv->dimmed_bar = NULL; - } - - if (priv->dimmed_plane != NULL) { - g_object_unref (priv->dimmed_plane); - priv->dimmed_plane = NULL; - } - - G_OBJECT_CLASS (parent_class)->dispose (G_OBJECT (sel)); -} - -static void -hildon_color_chooser_size_request (GtkWidget *widget, - GtkRequisition *req) -{ - GtkBorder inner, outer; - - init_borders (widget, &inner, &outer); - - req->width = inner.left + inner.top + inner.bottom + outer.left + outer.right; - req->height = inner.right + outer.top + outer.bottom; -} - -static void -hildon_color_chooser_size_allocate (GtkWidget *widget, - GtkAllocation *alloc) -{ - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - GtkBorder outer, inner; - - g_assert (priv); - - widget->allocation = *alloc; - - init_borders(widget, &inner, &outer); - - priv->hba.height = alloc->height - outer.top - outer.bottom; - priv->hba.y = alloc->y + outer.top; - priv->hba.width = inner.top; - priv->hba.x = alloc->x + alloc->width - outer.right - inner.top; - - priv->spa.x = alloc->x + outer.left; - priv->spa.y = alloc->y + outer.top; - priv->spa.height = alloc->height - outer.top - outer.bottom; - priv->spa.width = alloc->width - outer.left - outer.right - inner.top - inner.bottom; - - if (GTK_WIDGET_REALIZED (widget)) { - gdk_window_move_resize (priv->event_window, - widget->allocation.x, - widget->allocation.y, - widget->allocation.width, - widget->allocation.height); - } -} - -static void -hildon_color_chooser_realize (GtkWidget *widget) -{ - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - - g_assert (priv); - GdkWindowAttr attributes; - gint attributes_mask; - - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_ONLY; - attributes.window_type = GDK_WINDOW_CHILD; - - attributes.event_mask = gtk_widget_get_events (widget) | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK | - GDK_BUTTON_MOTION_MASK | - GDK_BUTTON1_MOTION_MASK; - - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_WMCLASS; - priv->event_window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); - - - gdk_window_set_user_data (priv->event_window, widget); - - GTK_WIDGET_CLASS (parent_class)->realize (widget); -} - -static void -hildon_color_chooser_unrealize (GtkWidget *widget) -{ - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - - g_assert (priv); - - if (priv->event_window) { - gdk_window_set_user_data (priv->event_window, NULL); - gdk_window_destroy (priv->event_window); - priv->event_window = NULL; - } - - GTK_WIDGET_CLASS(parent_class)->unrealize(widget); -} - -static void -hildon_color_chooser_map (GtkWidget *widget) -{ - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - - g_assert (priv); - GTK_WIDGET_CLASS(parent_class)->map(widget); - - if (priv->event_window) { - gdk_window_show (priv->event_window); - } -} - -static void -hildon_color_chooser_unmap (GtkWidget *widget) -{ - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - - g_assert (priv); - - if (priv->event_window) { - gdk_window_hide (priv->event_window); - } - - GTK_WIDGET_CLASS (parent_class)->unmap (widget); -} - -inline void -inline_clip_to_alloc (void *s, - GtkAllocation *a) -{ - struct { - int x, y, w, h; - } *area = s; - - - if (area->x < a->x) { - area->w -= a->x - area->x; - area->x = a->x; - } if (area->y < a->y) { - area->h -= a->y - area->y; - area->y = a->y; - } - if (area->x + area->w > a->x + a->width) - area->w = a->width - (area->x - a->x); - - if (area->y + area->h > a->y + a->height) - area->h = a->height - (area->y - a->y); -} - -static gboolean -hildon_color_chooser_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - HildonColorChooser *sel = HILDON_COLOR_CHOOSER (widget); - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - - g_assert (priv); - - GtkBorder graphical_border; - - struct { - int x, y, w, h; - } area; - - - if(! GTK_WIDGET_REALIZED (widget)) { - return FALSE; - } - - get_border (widget, "graphic_border", &graphical_border); - - if (event->area.width || event->area.height) { - - gdk_draw_rectangle (widget->window, - widget->style->black_gc, - FALSE, - priv->hba.x - 2, - priv->hba.y - 2, - priv->hba.width + 3, - priv->hba.height + 3); - - gdk_draw_rectangle (widget->window, - widget->style->black_gc, - FALSE, - priv->spa.x - 2, - priv->spa.y - 2, - priv->spa.width + 3, - priv->spa.height + 3); - } - - if (priv->expose_info.expose_queued) { - if (GTK_WIDGET_SENSITIVE (widget)) { - inline_draw_hue_bar (widget, priv->hba.x, priv->hba.y, priv->hba.width, priv->hba.height, priv->hba.y, priv->hba.height); - - inline_draw_sv_plane (sel, priv->spa.x, priv->spa.y, priv->spa.width, priv->spa.height); - } else { - inline_draw_hue_bar_dimmed (widget, priv->hba.x, priv->hba.y, priv->hba.width, priv->hba.height, priv->hba.y, priv->hba.height); - - inline_draw_sv_plane_dimmed (sel, priv->spa.x, priv->spa.y, priv->spa.width, priv->spa.height); - } - - priv->expose_info.expose_queued = 0; - - g_get_current_time (&priv->expose_info.last_expose_time); - - } else { - /* clip hue bar region */ - area.x = event->area.x; - area.y = event->area.y; - area.w = event->area.width; - area.h = event->area.height; - - inline_clip_to_alloc (&area, &priv->hba); - - if(GTK_WIDGET_SENSITIVE (widget)) { - inline_draw_hue_bar (widget, area.x, area.y, area.w, area.h, priv->hba.y, priv->hba.height); - } else { - inline_draw_hue_bar_dimmed (widget, area.x, area.y, area.w, area.h, priv->hba.y, priv->hba.height); - } - - area.x = event->area.x; - area.y = event->area.y; - area.w = event->area.width; - area.h = event->area.height; - - inline_clip_to_alloc (&area, &priv->spa); - - if (GTK_WIDGET_SENSITIVE (widget)) { - inline_draw_sv_plane (sel, area.x, area.y, area.w, area.h); - } else { - inline_draw_sv_plane_dimmed (sel, area.x, area.y, area.w, area.h); - } - } - - return FALSE; -} - - -inline void -inline_sub_times (GTimeVal *result, - GTimeVal *greater, - GTimeVal *lesser) -{ - result->tv_sec = greater->tv_sec - lesser->tv_sec; - result->tv_usec = greater->tv_usec - lesser->tv_usec; - - if (result->tv_usec < 0) { - result->tv_sec--; - result->tv_usec += 1000000; - } -} - -inline void -inline_limited_expose (HildonColorChooser *sel) -{ - GTimeVal curr_time, result; - GdkEventExpose event; - HildonColorChooserPrivate *priv; - - if (! GTK_WIDGET_REALIZED (GTK_WIDGET (sel))) { - return; - } - - priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (sel); - g_assert (priv); - - if(priv->currhue == priv->expose_info.last_expose_hue) { - return; /* no need to redraw */ - } - - priv->expose_info.last_expose_hue = priv->currhue; - - g_get_current_time (&curr_time); - - inline_sub_times (&result, &curr_time, &priv->expose_info.last_expose_time); - - if(result.tv_sec != 0 || result.tv_usec >= EXPOSE_INTERVAL) { - - priv->expose_info.expose_queued = 1; - - event.type = GDK_EXPOSE; - event.area.width = 0; - event.area.height = 0; - event.window = GTK_WIDGET(sel)->window; - - gtk_widget_send_expose(GTK_WIDGET(sel), (GdkEvent *)&event); - - } else if(! priv->expose_info.expose_queued) { - priv->expose_info.expose_queued = 1; - gdk_threads_add_timeout ((EXPOSE_INTERVAL - result.tv_usec) / 1000, hildon_color_chooser_expose_timer, sel); - } -} - -static gboolean -hildon_color_chooser_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - HildonColorChooser *sel = HILDON_COLOR_CHOOSER (widget); - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - - g_assert (priv); - int x, y, tmp; - - x = (int) event->x + widget->allocation.x; - y = (int) event->y + widget->allocation.y; - - if (x >= priv->spa.x && x <= priv->spa.x + priv->spa.width && - y >= priv->spa.y && y <= priv->spa.y + priv->spa.height) { - - tmp = y - priv->spa.y; - priv->currsat = tmp * 0xffff / priv->spa.height; - tmp = x - priv->spa.x; - priv->currval = tmp * 0xffff / priv->spa.width; - - g_signal_emit (sel, color_chooser_signals[COLOR_CHANGED], 0); - gtk_widget_queue_draw (widget); - - priv->mousestate = 1; - priv->mousein = TRUE; - - gtk_grab_add(widget); - - } else if (x >= priv->hba.x && x <= priv->hba.x + priv->hba.width && - y >= priv->hba.y && y <= priv->hba.y + priv->hba.height) { - - tmp = y - priv->hba.y; - priv->currhue = tmp * 0xffff / priv->hba.height; - - g_signal_emit (sel, color_chooser_signals[COLOR_CHANGED], 0); - inline_limited_expose (sel); - - priv->mousestate = 2; - priv->mousein = TRUE; - - gtk_grab_add (widget); - } - - return FALSE; -} - -static gboolean -hildon_color_chooser_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - - g_assert (priv); - - if (priv->mousestate) { - gtk_grab_remove (widget); - } - - priv->mousestate = 0; - priv->mousein = FALSE; - - return FALSE; -} - -static gboolean -hildon_color_chooser_pointer_motion (GtkWidget *widget, - GdkEventMotion *event) -{ - HildonColorChooser *sel = HILDON_COLOR_CHOOSER (widget); - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - - gint x, y, tmp; - - g_assert (priv); - - x = (int) event->x + widget->allocation.x; - y = (int) event->y + widget->allocation.y; - - if (priv->mousestate == 1) { - if (x >= priv->spa.x && x <= priv->spa.x + priv->spa.width && - y >= priv->spa.y && y <= priv->spa.y + priv->spa.height) { - - priv->currsat = (((long)(y - priv->spa.y)) * 0xffff) / priv->spa.height; - priv->currval = (((long)(x - priv->spa.x)) * 0xffff) / priv->spa.width; - - g_signal_emit (sel, color_chooser_signals[COLOR_CHANGED], 0); - gtk_widget_queue_draw(widget); - - } else if (priv->mousein == TRUE) { - } - - } else if (priv->mousestate == 2) { - if (x >= priv->hba.x && x <= priv->hba.x + priv->hba.width && - y >= priv->hba.y && y <= priv->hba.y + priv->hba.height) { - tmp = y - priv->hba.y; - tmp *= 0xffff; - tmp /= priv->hba.height; - - if(tmp != priv->currhue) { - priv->currhue = tmp; - - g_signal_emit (sel, color_chooser_signals[COLOR_CHANGED], 0); - inline_limited_expose (sel); - } - - } else if (priv->mousein == TRUE) { - } - } - - gdk_event_request_motions (event); - - return FALSE; -} - -static void -get_border (GtkWidget *w, - char *name, - GtkBorder *b) -{ - GtkBorder *tb = NULL; - - gtk_widget_style_get (w, name, &tb, NULL); - - if (tb) { - *b = *tb; - gtk_border_free (tb); - } else { - b->left = 0; - b->right = 0; - b->top = 0; - b->bottom = 0; - } -} - -static void -init_borders (GtkWidget *w, - GtkBorder *inner, - GtkBorder *outer) -{ - GtkBorder *tb; - - get_border (w, "outer_border", outer); - - gtk_widget_style_get (w, "inner_size", &tb, NULL); - - if (tb) { - *inner = *tb; - gtk_border_free (tb); - } else { - inner->left = 64; - inner->right = 64; - inner->top = 12; - inner->bottom = 2; - } - - if (inner->left < 2) inner->left = 2; - if (inner->right < 2) inner->right = 2; - if (inner->top < 2) inner->top = 2; -} - -/** - * hildon_color_chooser_set_color: - * @chooser: a #HildonColorChooser - * @color: a color to be set - * - * Sets the color selected in the widget. - * Will move the crosshair pointer to indicate the passed color. - */ -void -hildon_color_chooser_set_color (HildonColorChooser *chooser, - GdkColor *color) -{ - unsigned short hue, sat, val; - unsigned long min, max; - signed long tmp, diff; - HildonColorChooserPrivate *priv; - - g_return_if_fail (HILDON_IS_COLOR_CHOOSER (chooser)); - g_return_if_fail (color != NULL); - - priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (chooser); - g_assert (priv); - - /* ugly nesting */ - min = MIN (MIN (color->red, color->green), color->blue); - max = MAX (MAX (color->red, color->green), color->blue); - diff = max - min; - - val = max; - - if (val > 0 && diff != 0) { - sat = (diff * 0x0000ffff) / max; - - if (color->red == max) { - tmp = (signed) color->green - (signed) color->blue; - tmp *= 10922; - tmp /= diff; - if(tmp < 0) { - tmp += 65532; - } - hue = tmp; - } else if (color->green == max) { - hue = (((signed long) color->blue - (signed long)color->red) * 10922 / diff) + 21844; - } else { - hue = (((signed long) color->red -(signed long) color->green) * 10922 / diff) + 43688; - } - } else { - hue = 0; - sat = 0; - } - - priv->currhue = hue; - priv->currsat = sat; - priv->currval = val; - - inline_limited_expose (chooser); - g_signal_emit (chooser, color_chooser_signals[COLOR_CHANGED], 0); -} - -inline void -inline_h2rgb (unsigned short hue, - unsigned long *rgb) -{ - unsigned short hue_rotation, hue_value; - - hue_rotation = hue / 10922; - hue_value = hue % 10922; - - switch (hue_rotation) { - - case 0: - case 6: - rgb[0] = FULL_COLOR; - rgb[1] = hue_value * 6*256; - rgb[2] = 0; - break; - - case 1: - rgb[0] = FULL_COLOR - (hue_value * 6*256); - rgb[1] = FULL_COLOR; - rgb[2] = 0; - break; - - case 2: - rgb[0] = 0; - rgb[1] = FULL_COLOR; - rgb[2] = hue_value * 6*256; - break; - - case 3: - rgb[0] = 0; - rgb[1] = FULL_COLOR - (hue_value * 6*256); - rgb[2] = FULL_COLOR; - break; - - case 4: - rgb[0] = hue_value * 6*256; - rgb[1] = 0; - rgb[2] = FULL_COLOR; - break; - - case 5: - rgb[0] = FULL_COLOR; - rgb[1] = 0; - rgb[2] = FULL_COLOR - (hue_value * 6*256); - break; - - default: - rgb[0] = 0; - rgb[1] = 0; - rgb[2] = 0; - break; - } -} - -static void -intern_h2rgb8 (unsigned short hue, - unsigned char *rgb) -{ - unsigned short hue_rotation, hue_value; - - hue >>= 8; - hue_rotation = hue / 42; - hue_value = hue % 42; - - switch (hue_rotation) { - case 0: - case 6: - rgb[0] = FULL_COLOR8; - rgb[1] = hue_value * 6; - rgb[2] = 0; - break; - - case 1: - rgb[0] = FULL_COLOR8 - (hue_value * 6); - rgb[1] = FULL_COLOR8; - rgb[2] = 0; - break; - - case 2: - rgb[0] = 0; - rgb[1] = FULL_COLOR8; - rgb[2] = hue_value * 6; - break; - - case 3: - rgb[0] = 0; - rgb[1] = FULL_COLOR8 - (hue_value * 6); - rgb[2] = FULL_COLOR8; - break; - - case 4: - rgb[0] = hue_value * 6; - rgb[1] = 0; - rgb[2] = FULL_COLOR8; - break; - - case 5: - rgb[0] = FULL_COLOR8; - rgb[1] = 0; - rgb[2] = FULL_COLOR8 - (hue_value * 6); - break; - - default: - rgb[0] = 0; - rgb[1] = 0; - rgb[2] = 0; - break; - } -} - -/* optimization: do not ask hue for each round but have bilinear vectors */ -/* rethink: benefits from handling data 8 bit? (no shift round) */ -inline void -inline_draw_hue_bar (GtkWidget *widget, - int x, - int y, - int w, - int h, - int sy, - int sh) -{ - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (widget); - - unsigned short hvec, hcurr; - unsigned char *buf, *ptr, tmp[3]; - int i, j, tmpy; - g_assert (priv); - - if (w <= 0 || h <= 0) { - return; - } - - buf = (unsigned char *) g_malloc (w * h * 3); - - hvec = 65535 / sh; - hcurr = hvec * (y - sy); - - ptr = buf; - - for (i = 0; i < h; i++) { - intern_h2rgb8 (hcurr, tmp); - - for (j = 0; j < w; j++) { - ptr[0] = tmp[0]; - ptr[1] = tmp[1]; - ptr[2] = tmp[2]; - ptr += 3; - } - - hcurr += hvec; - } - - - gdk_draw_rgb_image (widget->parent->window, - widget->style->fg_gc[0], - x, y, - w, h, - GDK_RGB_DITHER_NONE, buf, w * 3); - - tmpy = priv->hba.y + (priv->currhue * priv->hba.height / 0xffff); - gdk_draw_line (widget->parent->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], priv->hba.x, tmpy, priv->hba.x + priv->hba.width - 1, tmpy); - - if ((((priv->currhue * priv->hba.height) & 0xffff) > 0x8000) && (tmpy < (priv->hba.y + priv->hba.height))) { - gdk_draw_line (widget->parent->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->hba.x, tmpy+1, priv->hba.x + priv->hba.width - 1, tmpy+1); - } else if (tmpy > priv->hba.y) { - gdk_draw_line(widget->parent->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], priv->hba.x, - tmpy-1, priv->hba.x + priv->hba.width - 1, tmpy-1); - } - - g_free(buf); -} - -inline void -inline_draw_hue_bar_dimmed (GtkWidget *widget, - int x, - int y, - int w, - int h, - int sy, - int sh) -{ - HildonColorChooser *sel = HILDON_COLOR_CHOOSER (widget); - HildonColorChooserPrivate *priv; - - if (w <= 0 || h <= 0) { - return; - } - - priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (sel); - g_assert (priv); - - /* We need to create (and cache) the pixbuf if we don't - * have it yet */ - if (priv->dimmed_bar == NULL) { - int i, j; - unsigned short hvec, hcurr, avg; - unsigned char *buf, *ptr, tmp[3]; - buf = (unsigned char *) g_malloc (w * h * 3); - - hvec = 65535 / sh; - hcurr = hvec * (y - sy); - ptr = buf; - - for (i = 0; i < h; i++) { - intern_h2rgb8 (hcurr, tmp); - - for(j = 0; j < w; j++) { - avg = ((unsigned short) tmp[0]*3 + (unsigned short) tmp[1]*2 + (unsigned short) tmp[2])/6; - ptr[0] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255); - ptr[1] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255); - ptr[2] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255); - ptr += 3; - } - - hcurr += hvec; - } - - priv->dimmed_bar = gdk_pixbuf_new_from_data (buf, GDK_COLORSPACE_RGB, FALSE, 8, w, h, w * 3, (gpointer) g_free, buf); - } - - gdk_draw_pixbuf (widget->parent->window, widget->style->fg_gc [0], priv->dimmed_bar, 0, 0, x, y, w, h, GDK_RGB_DITHER_NONE, 0, 0); -} - -inline void -inline_draw_crosshair (unsigned char *buf, - int x, - int y, - int w, - int h) -{ - int i, j, sx, sy; - - /* bad "clipping", clip the loop to save cpu */ - for(i = 0; i < 8; i++) { - for(j = 0; j < 8; j++) { - sx = j + x; sy = i + y; - - if (sx >= 0 && sx < w && sy >= 0 && sy < h) { - if (crosshair[j + 8*i]) { - if (crosshair[j + 8*i] & 0x1) { - buf[(sx)*3+(sy)*w*3+0] = 255; - buf[(sx)*3+(sy)*w*3+1] = 255; - buf[(sx)*3+(sy)*w*3+2] = 255; - } else { - buf[(sx)*3+(sy)*w*3+0] = 0; - buf[(sx)*3+(sy)*w*3+1] = 0; - buf[(sx)*3+(sy)*w*3+2] = 0; - } - } - } - } - } -} - -inline void -inline_draw_sv_plane (HildonColorChooser *sel, - int x, - int y, - int w, - int h) -{ - GtkWidget *widget = GTK_WIDGET (sel); - unsigned char *buf, *ptr; - unsigned long rgbx[3] = { 0x00ffffff, 0x00ffffff, 0x00ffffff }, rgbtmp[3]; - signed long rgby[3]; - HildonColorChooserPrivate *priv; - int i, j; - int tmp; - - if (w <= 0 || h <= 0) { - return; - } - - priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (sel); - g_assert (priv); - tmp = priv->spa.width * priv->spa.height; - - buf = (unsigned char *) g_malloc (w * h * 3); - ptr = buf; - - inline_h2rgb (priv->currhue, rgbtmp); - - rgby[0] = rgbtmp[0] - rgbx[0]; - rgby[1] = rgbtmp[1] - rgbx[1]; - rgby[2] = rgbtmp[2] - rgbx[2]; - - rgbx[0] /= priv->spa.width; - rgbx[1] /= priv->spa.width; - rgbx[2] /= priv->spa.width; - - rgby[0] /= tmp; - rgby[1] /= tmp; - rgby[2] /= tmp; - - rgbx[0] += (y - priv->spa.y) * rgby[0]; - rgbx[1] += (y - priv->spa.y) * rgby[1]; - rgbx[2] += (y - priv->spa.y) * rgby[2]; - - for(i = 0; i < h; i++) { - rgbtmp[0] = rgbx[0] * (x - priv->spa.x); - rgbtmp[1] = rgbx[1] * (x - priv->spa.x); - rgbtmp[2] = rgbx[2] * (x - priv->spa.x); - - for(j = 0; j < w; j++) { - ptr[0] = rgbtmp[0] >> 16; - ptr[1] = rgbtmp[1] >> 16; - ptr[2] = rgbtmp[2] >> 16; - rgbtmp[0] += rgbx[0]; - rgbtmp[1] += rgbx[1]; - rgbtmp[2] += rgbx[2]; - ptr += 3; - } - - rgbx[0] += rgby[0]; - rgbx[1] += rgby[1]; - rgbx[2] += rgby[2]; - } - - inline_draw_crosshair (buf, - (priv->spa.width * priv->currval / 0xffff) - x + priv->spa.x - 4, - (priv->spa.height * priv->currsat / 0xffff) - y + priv->spa.y - 4, - w, h); - - gdk_draw_rgb_image (widget->parent->window, widget->style->fg_gc[0], x, y, w, h, GDK_RGB_DITHER_NONE, buf, w * 3); - g_free(buf); -} - -inline void -inline_draw_sv_plane_dimmed (HildonColorChooser *sel, - int x, - int y, - int w, - int h) -{ - GtkWidget *widget = GTK_WIDGET (sel); - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (sel); - - g_assert (priv); - - if (w <= 0 || h <= 0) { - return; - } - - /* We need to create (and cache) the pixbuf if we don't - * have it yet */ - if (priv->dimmed_plane == NULL) { - unsigned char *buf, *ptr; - unsigned long rgbx[3] = { 0x00ffffff, 0x00ffffff, 0x00ffffff }, rgbtmp[3]; - unsigned long avg; - signed long rgby[3]; - int tmp = priv->spa.width * priv->spa.height, i, j; - - buf = (unsigned char *) g_malloc (w * h * 3); - - ptr = buf; - - /* possibe optimization: as we are drawing grayscale plane, there might - be some simpler algorithm to do this*/ - rgbtmp[0] = 0x00ffffff; - rgbtmp[1] = 0x00000000; - rgbtmp[2] = 0x00000000; - - rgby[0] = rgbtmp[0] - rgbx[0]; - rgby[1] = rgbtmp[1] - rgbx[1]; - rgby[2] = rgbtmp[2] - rgbx[2]; - - rgbx[0] /= priv->spa.width; - rgbx[1] /= priv->spa.width; - rgbx[2] /= priv->spa.width; - - rgby[0] /= tmp; - rgby[1] /= tmp; - rgby[2] /= tmp; - - rgbx[0] += (y - priv->spa.y) * rgby[0]; - rgbx[1] += (y - priv->spa.y) * rgby[1]; - rgbx[2] += (y - priv->spa.y) * rgby[2]; - - for(i = 0; i < h; i++) { - rgbtmp[0] = rgbx[0] * (x - priv->spa.x); - rgbtmp[1] = rgbx[1] * (x - priv->spa.x); - rgbtmp[2] = rgbx[2] * (x - priv->spa.x); - - for(j = 0; j < w; j++) { - avg = (rgbtmp[0] + rgbtmp[1] + rgbtmp[2])/3; - avg >>= 16; - ptr[0] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255); - ptr[1] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255); - ptr[2] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255); - rgbtmp[0] += rgbx[0]; - rgbtmp[1] += rgbx[1]; - rgbtmp[2] += rgbx[2]; - ptr += 3; - } - - rgbx[0] += rgby[0]; - rgbx[1] += rgby[1]; - rgbx[2] += rgby[2]; - } - - priv->dimmed_plane = gdk_pixbuf_new_from_data (buf, GDK_COLORSPACE_RGB, FALSE, 8, w, h, w * 3, (gpointer) g_free, buf); - } - - gdk_draw_pixbuf (widget->parent->window, widget->style->fg_gc [0], priv->dimmed_plane, 0, 0, x, y, w, h, GDK_RGB_DITHER_NONE, 0, 0); -} - - -static gboolean -hildon_color_chooser_expose_timer (gpointer data) -{ - HildonColorChooser *sel = HILDON_COLOR_CHOOSER (data); - HildonColorChooserPrivate *priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (sel); - - g_assert (priv); - - if (priv->expose_info.expose_queued) { - gtk_widget_queue_draw (GTK_WIDGET (data)); - } - - return FALSE; -} - -/** - * hildon_color_chooser_get_color: - * @chooser: a #HildonColorChooser - * @color: a color structure to fill with the currently selected color - * - * Retrives the currently selected color in the chooser. - * - */ -void -hildon_color_chooser_get_color (HildonColorChooser *chooser, - GdkColor *color) -{ - HildonColorChooserPrivate *priv; - GdkVisual *system_visual = gdk_visual_get_system (); - unsigned long rgb[3], rgb2[3]; - - g_return_if_fail (HILDON_IS_COLOR_CHOOSER (chooser)); - g_return_if_fail (color != NULL); - - priv = HILDON_COLOR_CHOOSER_GET_PRIVATE (chooser); - g_assert (priv); - - inline_h2rgb (priv->currhue, rgb); - - rgb2[0] = 0xffffff - rgb[0]; - rgb2[1] = 0xffffff - rgb[1]; - rgb2[2] = 0xffffff - rgb[2]; - - color->red = ((rgb[0] >> 8) + ((rgb2[0] >> 8) * (0xffff - priv->currsat) / 0xffff)) * priv->currval / 0xffff; - color->green = ((rgb[1] >> 8) + ((rgb2[1] >> 8) * (0xffff - priv->currsat) / 0xffff)) * priv->currval / 0xffff; - color->blue = ((rgb[2] >> 8) + ((rgb2[2] >> 8) * (0xffff - priv->currsat) / 0xffff)) * priv->currval / 0xffff; - - color->pixel = ((color->red >> (16 - system_visual->red_prec)) << system_visual->red_shift) | - ((color->green >> (16 - system_visual->green_prec)) << system_visual->green_shift) | - ((color->blue >> (16 - system_visual->blue_prec)) << system_visual->blue_shift); -} - -/** - * hildon_color_chooser_new: - * - * Creates a new #HildonColorChooser. - * - * Returns: the new #HildonColorChooser - **/ -GtkWidget* -hildon_color_chooser_new (void) -{ - return (GtkWidget *) g_object_new (HILDON_TYPE_COLOR_CHOOSER, NULL); -} - -static void -hildon_color_chooser_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - g_return_if_fail (HILDON_IS_COLOR_CHOOSER (object)); - - switch (param_id) - { - - case PROP_COLOR: { - GdkColor *color = g_value_get_boxed (value); - hildon_color_chooser_set_color ((HildonColorChooser *) object, color); - } break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -hildon_color_chooser_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - g_return_if_fail (HILDON_IS_COLOR_CHOOSER (object)); - - switch (param_id) - { - - case PROP_COLOR: { - GdkColor color; - hildon_color_chooser_get_color ((HildonColorChooser *) object, &color); - g_value_set_boxed (value, &color); - } break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - diff --git a/hildon/hildon-color-chooser.h b/hildon/hildon-color-chooser.h deleted file mode 100644 index bcc8e4d..0000000 --- a/hildon/hildon-color-chooser.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Author: Kuisma Salonen <kuisma.salonen@nokia.com> - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_COLOR_CHOOSER_H__ -#define __HILDON_COLOR_CHOOSER_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_COLOR_CHOOSER \ - (hildon_color_chooser_get_type()) - -#define HILDON_COLOR_CHOOSER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - HILDON_TYPE_COLOR_CHOOSER, \ - HildonColorChooser)) - -#define HILDON_COLOR_CHOOSER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - HILDON_TYPE_COLOR_CHOOSER, \ - HildonColorChooserClass)) - -#define HILDON_IS_COLOR_CHOOSER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - HILDON_TYPE_COLOR_CHOOSER)) - -typedef struct _HildonColorChooser HildonColorChooser; - -typedef struct _HildonColorChooserClass HildonColorChooserClass; - -struct _HildonColorChooser -{ - GtkWidget parent; -}; - -struct _HildonColorChooserClass -{ - GtkWidgetClass parent; - - void (*color_changed) (HildonColorChooser *selection, GdkColor *color); - void (*set_color) (HildonColorChooser *, GdkColor *); -}; - -GType G_GNUC_CONST -hildon_color_chooser_get_type (void); - -GtkWidget* -hildon_color_chooser_new (void); - -void -hildon_color_chooser_set_color (HildonColorChooser *chooser, - GdkColor *color); - -void -hildon_color_chooser_get_color (HildonColorChooser *chooser, - GdkColor *color); - -G_END_DECLS - -#endif /* __HILDON_COLOR_CHOOSER_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-controlbar-private.h b/hildon/hildon-controlbar-private.h deleted file mode 100644 index 49983af..0000000 --- a/hildon/hildon-controlbar-private.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_CONTROLBAR_PRIVATE_H__ -#define __HILDON_CONTROLBAR_PRIVATE_H__ - -G_BEGIN_DECLS - -typedef struct _HildonControlbarPrivate HildonControlbarPrivate; - -#define HILDON_CONTROLBAR_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\ - HILDON_TYPE_CONTROLBAR, HildonControlbarPrivate)); - -struct _HildonControlbarPrivate -{ - gboolean button_press; - gint old_value; -}; - -G_END_DECLS - -#endif /* __HILDON_CONTROLBAR_PRIVATE_H__ */ diff --git a/hildon/hildon-controlbar.c b/hildon/hildon-controlbar.c deleted file mode 100644 index e9b4d8e..0000000 --- a/hildon/hildon-controlbar.c +++ /dev/null @@ -1,893 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-controlbar - * @short_description: A widget that allows increasing or decreasing - * a value within a pre-defined range. - * - * #HildonControlbar is a horizontally positioned range widget that is - * visually divided into blocks and supports setting a minimum and - * maximum value for the range. - * - * <note> - * <para> - * #HildonControlbar has been deprecated since Hildon 2.2 - * See <link linkend="hildon-migrating-control-bar">Migrating Control Bars</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <title>HildonControlbar example</title> - * <programlisting> - * GtkWidget *cbar = hildon_controlbar_new(); - * hildon_controlbar_set_max (HILDON_CONTROLBAR (cbar), 12); - * hildon_controlbar_set_value (HILDON_CONTROLBAR (cbar), 6); - * </programlisting> - * </example> - * - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <math.h> -#include <libintl.h> -#include <gdk/gdk.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-controlbar.h" -#include "hildon-controlbar-private.h" - -#define _(string)\ - dgettext("hildon-libs", string) - -#define DEFAULT_WIDTH 234 - -#define DEFAULT_HEIGHT 60 - -#define DEFAULT_BORDER_WIDTH 0 - -#define HILDON_CONTROLBAR_STEP_INCREMENT 1 - -#define HILDON_CONTROLBAR_PAGE_INCREMENT 1 - -#define HILDON_CONTROLBAR_PAGE_SIZE 0 - -#define HILDON_CONTROLBAR_UPPER_VALUE 10 - -#define HILDON_CONTROLBAR_LOWER_VALUE 0.0 - -#define HILDON_CONTROLBAR_INITIAL_VALUE 0 - -static GtkScaleClass* parent_class; - -enum -{ - PROP_0, - PROP_MIN = 1, - PROP_MAX, - PROP_VALUE -}; - -enum -{ - END_REACHED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -static void -hildon_controlbar_class_init (HildonControlbarClass *controlbar_class); - -static void -hildon_controlbar_init (HildonControlbar *controlbar); - -static GObject* -hildon_controlbar_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties); - -static gint -hildon_controlbar_button_press_event (GtkWidget *widget, - GdkEventButton * event); - -static gint -hildon_controlbar_button_release_event (GtkWidget *widget, - GdkEventButton *event); - -static gint -hildon_controlbar_expose_event (GtkWidget *widget, - GdkEventExpose *event); - -static void -hildon_controlbar_size_request (GtkWidget *self, - GtkRequisition *req); -static void -hildon_controlbar_paint (HildonControlbar *self, - GdkRectangle * area); - -static gboolean -hildon_controlbar_keypress (GtkWidget *widget, - GdkEventKey * event); - -static void -hildon_controlbar_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_controlbar_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void -hildon_controlbar_value_changed (GtkAdjustment *adj, - GtkRange *range); - -static gboolean -hildon_controlbar_change_value (GtkRange *range, - GtkScrollType scroll, - gdouble new_value, - gpointer data); - -/** - * hildon_controlbar_get_type: - * - * Initializes and returns the type of a hildon control bar. - * - * Returns: GType of #HildonControlbar - */ -GType G_GNUC_CONST -hildon_controlbar_get_type (void) -{ - static GType controlbar_type = 0; - - if (!controlbar_type) { - static const GTypeInfo controlbar_info = { - sizeof (HildonControlbarClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_controlbar_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonControlbar), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_controlbar_init, - }; - controlbar_type = g_type_register_static (GTK_TYPE_SCALE, - "HildonControlbar", - &controlbar_info, 0); - } - - return controlbar_type; -} - -static void -hildon_controlbar_class_init (HildonControlbarClass *controlbar_class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (controlbar_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (controlbar_class); - - parent_class = g_type_class_peek_parent(controlbar_class); - - g_type_class_add_private(controlbar_class, sizeof (HildonControlbarPrivate)); - - gobject_class->get_property = hildon_controlbar_get_property; - gobject_class->set_property = hildon_controlbar_set_property; - gobject_class->constructor = hildon_controlbar_constructor; - widget_class->size_request = hildon_controlbar_size_request; - widget_class->button_press_event = hildon_controlbar_button_press_event; - widget_class->button_release_event = hildon_controlbar_button_release_event; - widget_class->expose_event = hildon_controlbar_expose_event; - widget_class->key_press_event = hildon_controlbar_keypress; - controlbar_class->end_reached = NULL; - - /** - * HildonControlbar:min: - * - * Controlbar minimum value. - */ - g_object_class_install_property (gobject_class, PROP_MIN, - g_param_spec_int ("min", - "Minimum value", - "Smallest possible value", - G_MININT, G_MAXINT, - HILDON_CONTROLBAR_LOWER_VALUE, - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - /** - * HildonControlbar:max: - * - * Controlbar maximum value. - */ - g_object_class_install_property (gobject_class, PROP_MAX, - g_param_spec_int ("max", - "Maximum value", - "Greatest possible value", - G_MININT, G_MAXINT, - HILDON_CONTROLBAR_UPPER_VALUE, - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - /** - * HildonControlbar:value: - * - * Controlbar current value. - */ - g_object_class_install_property (gobject_class, PROP_VALUE, - g_param_spec_int ("value", - "Current value", - "Current value", - G_MININT, G_MAXINT, - HILDON_CONTROLBAR_INITIAL_VALUE, - G_PARAM_READABLE | G_PARAM_WRITABLE) ); - - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_uint ("inner_border_width", - "Inner border width", - "The border spacing between the controlbar border and controlbar blocks.", - 0, G_MAXINT, - DEFAULT_BORDER_WIDTH, - G_PARAM_READABLE)); - - signals[END_REACHED] = - g_signal_new("end-reached", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (HildonControlbarClass, end_reached), - NULL, NULL, - g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, - G_TYPE_BOOLEAN); -} - -static void -hildon_controlbar_init (HildonControlbar *controlbar) -{ - GtkRange *range; - HildonControlbarPrivate *priv; - - /* Initialize the private property */ - priv = HILDON_CONTROLBAR_GET_PRIVATE(controlbar); - g_assert (priv); - - priv->button_press = FALSE; - priv->old_value = 0; - range = GTK_RANGE (controlbar); - - range->round_digits = -1; - - gtk_widget_set_size_request (GTK_WIDGET (controlbar), - DEFAULT_WIDTH, - DEFAULT_HEIGHT); - - g_signal_connect (range, "change-value", - G_CALLBACK (hildon_controlbar_change_value), NULL); -} - -static GObject* -hildon_controlbar_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GObject *obj; - GtkAdjustment *adj; - - obj = G_OBJECT_CLASS (parent_class)->constructor (type, - n_construct_properties, construct_properties); - - gtk_scale_set_draw_value (GTK_SCALE (obj), FALSE); - - /* Initialize the GtkAdjustment of the controlbar*/ - adj = GTK_RANGE (obj)->adjustment; - adj->step_increment = HILDON_CONTROLBAR_STEP_INCREMENT; - adj->page_increment = HILDON_CONTROLBAR_PAGE_INCREMENT; - adj->page_size = HILDON_CONTROLBAR_PAGE_SIZE; - - g_signal_connect (adj, "value-changed", - G_CALLBACK (hildon_controlbar_value_changed), obj); - return obj; -} - -static void -hildon_controlbar_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonControlbar *controlbar = HILDON_CONTROLBAR (object); - - switch (param_id) - { - case PROP_MIN: - hildon_controlbar_set_min (controlbar, g_value_get_int(value)); - break; - - case PROP_MAX: - hildon_controlbar_set_max (controlbar, g_value_get_int(value)); - break; - - case PROP_VALUE: - hildon_controlbar_set_value (controlbar, g_value_get_int(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void hildon_controlbar_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - HildonControlbar *controlbar = HILDON_CONTROLBAR(object); - - switch (param_id) - { - case PROP_MIN: - g_value_set_int (value, hildon_controlbar_get_min (controlbar)); - break; - - case PROP_MAX: - g_value_set_int (value, hildon_controlbar_get_max (controlbar)); - break; - - case PROP_VALUE: - g_value_set_int (value, hildon_controlbar_get_value (controlbar)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -hildon_controlbar_value_changed (GtkAdjustment *adj, - GtkRange *range) -{ - HildonControlbarPrivate *priv = HILDON_CONTROLBAR_GET_PRIVATE(range); - g_assert (priv); - - /* Change the controlbar value if the adjusted value is large enough - * otherwise, keep the old value - */ - if (ABS(ceil (adj->value) - priv->old_value) >= 1) - { - priv->old_value = ceil (adj->value); - adj->value = priv->old_value; - } - else - g_signal_stop_emission_by_name (adj, "value-changed"); - - gtk_adjustment_set_value (adj, priv->old_value); -} - -/** - * hildon_controlbar_new: - * - * Creates a new #HildonControlbar widget. - * - * Returns: a #GtkWidget pointer of newly created control bar - * widget - */ -GtkWidget* -hildon_controlbar_new (void) -{ - return GTK_WIDGET (g_object_new (HILDON_TYPE_CONTROLBAR, NULL)); -} - -/* This function prevents Up and Down keys from changing the - * widget's value (like Left and Right). - * Instead they are used for changing focus to other widgtes. - */ -static gboolean -hildon_controlbar_keypress (GtkWidget *widget, - GdkEventKey *event) -{ - if (event->keyval == GDK_Up || event->keyval == GDK_Down) - return FALSE; - - return ((GTK_WIDGET_CLASS (parent_class)->key_press_event) (widget, event)); -} - -static void -hildon_controlbar_size_request (GtkWidget *self, - GtkRequisition *req) -{ - if (GTK_WIDGET_CLASS (parent_class)->size_request) - GTK_WIDGET_CLASS (parent_class)->size_request(self, req); - - req->width = DEFAULT_WIDTH; - req->height = DEFAULT_HEIGHT; -} - -/** - * hildon_controlbar_set_value: - * @self: pointer to #HildonControlbar - * @value: value in range of >= 0 && < G_MAX_INT - * - * Set the current value of the control bar to the specified value. - */ -void -hildon_controlbar_set_value (HildonControlbar * self, - gint value) -{ - GtkAdjustment *adj; - g_return_if_fail (HILDON_IS_CONTROLBAR (self)); - adj = GTK_RANGE (self)->adjustment; - - g_return_if_fail (value >= 0); - - if (value >= adj->upper) - value = adj->upper; - else if (value <= adj->lower) - value = adj->lower; - - adj->value = value; - gtk_adjustment_value_changed (adj); - - g_object_notify (G_OBJECT(self), "value"); -} - -/** - * hildon_controlbar_get_value: - * @self: pointer to #HildonControlbar - * - * Returns: current value as gint - */ -gint -hildon_controlbar_get_value (HildonControlbar * self) -{ - GtkAdjustment *adj; - g_return_val_if_fail (HILDON_IS_CONTROLBAR (self), 0); - adj = GTK_RANGE(self)->adjustment; - - return (gint) ceil(adj->value); -} - -/** - * hildon_controlbar_set_max: - * @self: pointer to #HildonControlbar - * @max: maximum value to set. The value needs to be greater than 0. - * - * Set the control bar's maximum to the given value. - * - * If the new maximum is smaller than current value, the value will be - * adjusted so that it equals the new maximum. - */ -void -hildon_controlbar_set_max (HildonControlbar * self, - gint max) -{ - GtkAdjustment *adj; - g_return_if_fail (HILDON_IS_CONTROLBAR (self)); - adj = GTK_RANGE (self)->adjustment; - - if (max < adj->lower) - max = adj->lower; - - if (adj->value > max) - hildon_controlbar_set_value (self, max); - - adj->upper = max; - gtk_adjustment_changed (adj); - - g_object_notify (G_OBJECT(self), "max"); -} - -/** - * hildon_controlbar_set_min: - * @self: pointer to #HildonControlbar - * @min: minimum value to set. The value needs to be greater than or - * equal to 0. - * - * Set the control bar's minimum to the given value. - * - * If the new minimum is smaller than current value, the value will be - * adjusted so that it equals the new minimum. - */ -void -hildon_controlbar_set_min (HildonControlbar *self, - gint min) -{ - GtkAdjustment *adj; - g_return_if_fail (HILDON_IS_CONTROLBAR (self)); - adj = GTK_RANGE (self)->adjustment; - - if (min > adj->upper) - min = adj->upper; - - if (adj->value < min) - hildon_controlbar_set_value (self, min); - - adj->lower = min; - gtk_adjustment_changed (adj); - g_object_notify (G_OBJECT(self), "min"); -} - -/** - * hildon_controlbar_set_range: - * @self: pointer to #HildonControlbar - * @max: maximum value to set. The value needs to be greater than 0. - * @min: Minimum value to set. The value needs to be greater than or - * equal to 0. - * - * Set the controlbars range to the given value - * - * If the new maximum is smaller than current value, the value will be - * adjusted so that it equals the new maximum. - * - * If the new minimum is smaller than current value, the value will be - * adjusted so that it equals the new minimum. - */ -void -hildon_controlbar_set_range (HildonControlbar *self, - gint min, - gint max) -{ - g_return_if_fail (HILDON_IS_CONTROLBAR (self)); - - if (min > max) - min = max; - - /* We need to set max first here, because when min is set before - * max is set, it would end up 0, because max can't be bigger than 0. - */ - hildon_controlbar_set_max (self, max); - hildon_controlbar_set_min (self, min); -} - -/** - * hildon_controlbar_get_max: - * @self: a pointer to #HildonControlbar - * - * Returns: maximum value of control bar - */ -gint hildon_controlbar_get_max (HildonControlbar *self) -{ - GtkAdjustment *adj; - g_return_val_if_fail (HILDON_IS_CONTROLBAR (self), 0); - adj = GTK_RANGE (self)->adjustment; - - return (gint) adj->upper; -} - -/** - * hildon_controlbar_get_min: - * @self: a pointer to #HildonControlbar - * - * Returns: minimum value of controlbar - */ -gint -hildon_controlbar_get_min (HildonControlbar *self) -{ - GtkAdjustment *adj = GTK_RANGE (self)->adjustment; - return (gint) adj->lower; -} - -/* - * Event handler for button press - * Need to change button1 to button2 before passing this event to - * parent handler. (see specs) - * Also updates button_press variable so that we can draw highlights - * correctly - */ -static gint -hildon_controlbar_button_press_event (GtkWidget *widget, - GdkEventButton *event) -{ - HildonControlbar *self; - HildonControlbarPrivate *priv; - gboolean result = FALSE; - - g_return_val_if_fail (widget, FALSE); - g_return_val_if_fail (event, FALSE); - - self = HILDON_CONTROLBAR (widget); - priv = HILDON_CONTROLBAR_GET_PRIVATE (self); - g_assert (priv); - - priv->button_press = TRUE; - event->button = event->button == 1 ? 2 : event->button; - - /* Ugh dirty hack. We manipulate the mouse event location to - compensate for centering the widget in case it is taller than the - default height. */ - if (widget->allocation.height > DEFAULT_HEIGHT) { - gint difference = widget->allocation.height - DEFAULT_HEIGHT; - - if (difference & 1) - difference += 1; - difference = difference / 2; - - event->y -= difference; - } - - - /* call the parent handler */ - if (GTK_WIDGET_CLASS (parent_class)->button_press_event) - result = GTK_WIDGET_CLASS (parent_class)->button_press_event(widget, event); - - return result; -} - -/* - * Purpose of this function is to prevent Up and Down keys from - * changing the widget's value (like Left and Right). Instead they - * are used for changing focus to other widgtes. - */ -static gboolean -hildon_controlbar_change_value (GtkRange *range, - GtkScrollType scroll, - gdouble new_value, - gpointer data) -{ - HildonControlbarPrivate *priv; - GtkAdjustment *adj = range->adjustment; - gdouble vv = adj->upper - adj->lower; - gint calc = ((new_value - adj->lower) / vv) * (vv + 1.0) + adj->lower; - - priv = HILDON_CONTROLBAR_GET_PRIVATE(range); - g_assert (priv); - - /* Emit a signal when upper or lower limit is reached */ - switch (scroll) - { - case GTK_SCROLL_STEP_FORWARD : - case GTK_SCROLL_PAGE_FORWARD : - if( adj->value == priv->old_value ) - if( adj->value == adj->upper ) - g_signal_emit( G_OBJECT(range), signals[END_REACHED], 0, TRUE ); - break; - - case GTK_SCROLL_STEP_BACKWARD : - case GTK_SCROLL_PAGE_BACKWARD : - if( adj->value == priv->old_value ) - if( adj->value == adj->lower ) - g_signal_emit( G_OBJECT(range), signals[END_REACHED], 0, FALSE ); - break; - - default: - break; - } - - GTK_RANGE_CLASS (parent_class)->change_value (range, scroll, calc); - - return TRUE; -} - -/* - * Event handler for button release - * Need to change button1 to button2 before passing this event to - * parent handler. (see specs) - * Also updates button_press variable so that we can draw hilites - * correctly - */ -static gint -hildon_controlbar_button_release_event (GtkWidget *widget, - GdkEventButton *event) -{ - HildonControlbar *self; - HildonControlbarPrivate *priv; - gboolean result = FALSE; - - g_return_val_if_fail (widget, FALSE); - g_return_val_if_fail (event, FALSE); - - self = HILDON_CONTROLBAR (widget); - priv = HILDON_CONTROLBAR_GET_PRIVATE (self); - g_assert (priv); - - priv->button_press = FALSE; - event->button = event->button == 1 ? 2 : event->button; - - /* call the parent handler */ - if (GTK_WIDGET_CLASS (parent_class)->button_release_event) - result = GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event); - - return result; -} - -/* - * Event handler for expose event - */ -static gint -hildon_controlbar_expose_event (GtkWidget *widget, - GdkEventExpose * event) -{ - HildonControlbar *self = NULL; - - gboolean result = FALSE; - gint old_height = -1; - gint old_y = -1; - - g_return_val_if_fail (event, FALSE); - g_return_val_if_fail (HILDON_IS_CONTROLBAR(widget), FALSE); - - self = HILDON_CONTROLBAR(widget); - - old_height = widget->allocation.height; - old_y = widget->allocation.y; - - if (widget->allocation.height > DEFAULT_HEIGHT) { - int difference = widget->allocation.height - DEFAULT_HEIGHT; - - if (difference & 1) - difference += 1; - - difference = difference / 2; - - widget->allocation.y += difference; - widget->allocation.height = DEFAULT_HEIGHT; - } - - /* call the parent handler */ - if (GTK_WIDGET_CLASS (parent_class)->expose_event) - result = GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event); - - hildon_controlbar_paint (self, &event->area); - - widget->allocation.height = old_height; - widget->allocation.y = old_y; - - return TRUE; -} - -/* - * Paint method. - * This is where all the work is actually done... - */ -static void -hildon_controlbar_paint (HildonControlbar *self, - GdkRectangle *area) -{ - HildonControlbarPrivate *priv; - GtkWidget *widget = GTK_WIDGET(self); - GtkAdjustment *ctrlbar = GTK_RANGE(self)->adjustment; - gint x = widget->allocation.x; - gint y = widget->allocation.y; - gint h = widget->allocation.height; - gint w = widget->allocation.width; - gint max = 0; - gint stepper_size = 0; - gint stepper_spacing = 0; - gint inner_border_width = 0; - gint block_area = 0, block_width = 0, block_x = 0, block_max = 0, block_height,block_y; - /* Number of blocks on the controlbar */ - guint block_count = 0; - /* Number of displayed active blocks */ - guint block_act = 0; - /* Minimum no. of blocks visible */ - guint block_min = 0; - gint separatingpixels = 2; - gint block_remains = 0; - gint i, start_x, end_x, current_width; - GtkStateType state = GTK_STATE_NORMAL; - - g_return_if_fail(area); - - priv = HILDON_CONTROLBAR_GET_PRIVATE(self); - g_assert (priv); - - if (GTK_WIDGET_SENSITIVE (self) == FALSE) - state = GTK_STATE_INSENSITIVE; - - gtk_widget_style_get (GTK_WIDGET (self), - "stepper-size", &stepper_size, - "stepper-spacing", &stepper_spacing, - "inner_border_width", &inner_border_width, NULL); - - block_area = (w - 2 * stepper_size - 2 * stepper_spacing - 2 * inner_border_width); - - if (block_area <= 0) - return; - - block_min = 1; - block_max = ctrlbar->upper - ctrlbar->lower + block_min; - block_act = priv->old_value - GTK_RANGE (self)->adjustment->lower + block_min; - - /* We check border width and maximum value and adjust - * separating pixels for block width here. If the block size would - * become too small, we make the separators smaller. Graceful fallback. - */ - max = ctrlbar->upper; - if(ctrlbar->upper == 0) - separatingpixels = 3; - else if ((block_area - ((max - 1) * 3)) / max >= 4) - separatingpixels = 3; - else if ((block_area - ((max - 1) * 2)) / max >= 4) - separatingpixels = 2; - else if ((block_area - ((max - 1) * 1)) / max >= 4) - separatingpixels = 1; - else - separatingpixels = 0; - - if (block_max == 0) - { - /* If block max is 0 then we dim the whole control. */ - state = GTK_STATE_INSENSITIVE; - block_width = block_area; - block_remains = 0; - block_max = 1; - } - else - { - block_width = - (block_area - (separatingpixels * (block_max - 1))) / block_max; - block_remains = - (block_area - (separatingpixels * (block_max - 1))) % block_max; - } - - block_x = x + stepper_size + stepper_spacing + inner_border_width; - block_y = y + inner_border_width; - block_height = h - 2 * inner_border_width; - - block_count = ctrlbar->value - ctrlbar->lower + block_min; - - if (block_count == 0) - block_count = 1; - /* Without this there is vertical block corruption when block_height = - 1. This should work from 0 up to whatever */ - - if (block_height < 2) - block_height = 2; - - /* - * Changed the drawing of the blocks completely, - * because of "do-not-resize-when-changing-max"-specs. - * Now the code calculates from the block_remains when - * it should add one pixel to the block and when not. - */ - - for (i = 1; i <= block_max; i++) { - - /* Here we calculate whether we add one pixel to current_width or - not. */ - start_x = block_width * (i - 1) + ((i - 1) * block_remains) / block_max; - end_x = block_width * i + (i * block_remains) / block_max; - current_width = end_x - start_x; - - gtk_paint_box (widget->style, widget->window, state, - (i <= block_count) ? GTK_SHADOW_IN : GTK_SHADOW_OUT, - NULL, widget, "hildon_block", - block_x, block_y, current_width, - block_height); - - /* We keep the block_x separate because of the - 'separatingpixels' */ - block_x += current_width + separatingpixels; - } - -} diff --git a/hildon/hildon-controlbar.h b/hildon/hildon-controlbar.h deleted file mode 100644 index fef579e..0000000 --- a/hildon/hildon-controlbar.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_CONTROLBAR_H__ -#define __HILDON_CONTROLBAR_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_CONTROLBAR \ - (hildon_controlbar_get_type()) - -#define HILDON_CONTROLBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_CONTROLBAR, HildonControlbar)) - -#define HILDON_CONTROLBAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_CONTROLBAR, HildonControlbarClass)) - -#define HILDON_IS_CONTROLBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_CONTROLBAR)) - -#define HILDON_IS_CONTROLBAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass),\ - HILDON_TYPE_CONTROLBAR)) - -#define HILDON_CONTROLBAR_GET_CLASS(obj) \ - ((HildonControlBarClass *) G_OBJECT_GET_CLASS(obj)) - -typedef struct _HildonControlbar HildonControlbar; - -typedef struct _HildonControlbarClass HildonControlbarClass; - -struct _HildonControlbar -{ - GtkScale scale; -}; - -struct _HildonControlbarClass -{ - GtkScaleClass parent_class; - void (*end_reached) (HildonControlbar *controlbar, gboolean end); -}; - -GType G_GNUC_CONST -hildon_controlbar_get_type (void); - -GtkWidget* -hildon_controlbar_new (void); - -void -hildon_controlbar_set_value (HildonControlbar *self, - gint value); - -gint -hildon_controlbar_get_value (HildonControlbar *self); - -gint -hildon_controlbar_get_max (HildonControlbar *self); - -gint -hildon_controlbar_get_min (HildonControlbar *self); - -void -hildon_controlbar_set_max (HildonControlbar *self, - gint max); - -void -hildon_controlbar_set_min (HildonControlbar *self, - gint min); - -void -hildon_controlbar_set_range (HildonControlbar *self, - gint min, - gint max); - -G_END_DECLS - -#endif /* __HILDON_CONTROLBAR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-date-editor-private.h b/hildon/hildon-date-editor-private.h deleted file mode 100644 index 3206172..0000000 --- a/hildon/hildon-date-editor-private.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_DATE_EDITOR_PRIVATE_H__ -#define __HILDON_DATE_EDITOR_PRIVATE_H__ - -G_BEGIN_DECLS - -#define HILDON_DATE_EDITOR_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE((obj),\ - HILDON_TYPE_DATE_EDITOR, HildonDateEditorPrivate)); - -typedef struct _HildonDateEditorPrivate HildonDateEditorPrivate; - -struct _HildonDateEditorPrivate -{ - /* Cache of values in the entries, used in setting only parts of the date */ - guint year; /* current year in the entry */ - guint month; /* current month in the entry */ - guint day; /* current day in the entry */ - - gboolean calendar_icon_pressed; - - GtkWidget *frame; /* borders around the date */ - GtkWidget *d_button_image; /* icon */ - GtkWidget *d_box_date; /* hbox for date */ - - GtkWidget *d_entry; /* GtkEntry for day */ - GtkWidget *m_entry; /* GtkEntry for month */ - GtkWidget *y_entry; /* GtkEntry for year */ - - GList *delims; /* List of delimeters between the fields - * (and possible at the ends) */ - GtkWidget *calendar_icon; - - gboolean skip_validation; /* don't validate date at all */ - - gint min_year; /* minimum year allowed */ - gint max_year; /* maximum year allowed */ -}; - -G_END_DECLS - -#endif /* __HILDON_DATE_EDITOR_PRIVATE_H__ */ diff --git a/hildon/hildon-date-editor.c b/hildon/hildon-date-editor.c deleted file mode 100644 index 6a89c3f..0000000 --- a/hildon/hildon-date-editor.c +++ /dev/null @@ -1,1567 +0,0 @@ -/* vim:set sw=4 expandtab cino=(0: - * - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-date-editor - * @short_description: A widget which queries a date from user or opens - * a HildonCalendarPopup. - * @see_also: #HildonCalendarPopup, #HildonTimeEditor - * - * HildonDateEditor is a widget with three entry fields (day, month, - * year) and an icon (button): clicking on the icon opens up a - * HildonCalendarPopup. - * - * - * <note> - * <para> - * #HildonDateEditor has been deprecated since Hildon 2.2 and should - * not be used in newly written code. Use #HildonDateSelector instead. See - * <link linkend="hildon-migrating-date-widgets">Migrating Date Widgets</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <programlisting> - * guint y, m, d; - * GtkDialog *dialog; - * GtkWidget *date_editor; - * <!-- --> - * dialog = GTK_DIALOG (gtk_dialog_new ()); - * date_editor = hildon_date_editor_new (); - * <!-- --> - * gtk_box_pack_start (GTK_BOX (dialog->vbox), gtk_label_new ("Choose a date"), FALSE, FALSE, 10); - * gtk_box_pack_start (GTK_BOX (dialog->vbox), date_editor, FALSE, FALSE, 10); - * gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CANCEL); - * <!-- --> - * gtk_widget_show_all (GTK_WIDGET (dialog)); - * gtk_dialog_run (dialog); - * <!-- --> - * hildon_date_editor_get_date (HILDON_DATE_EDITOR (date_editor), &y, &m, &d); - * g_debug ("Date: %u-%u-%u", y, m, d); - * <!-- --> - * </programlisting> - * </example> - * - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <time.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <libintl.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-date-editor.h" -#include "hildon-calendar-popup.h" -#include "hildon-defines.h" -#include "hildon-marshalers.h" -#include "hildon-enum-types.h" -#include "hildon-time-editor.h" -#include "hildon-banner.h" -#include "hildon-date-editor-private.h" -#include "hildon-private.h" - -#define _(string) dgettext("hildon-libs", string) - -#define c_(string) dgettext("hildon-common-strings", string) - -#define ENTRY_BORDERS 11 - -#define DATE_EDITOR_HEIGHT 30 - -#define DAY_ENTRY_WIDTH 2 - -#define MONTH_ENTRY_WIDTH 2 - -#define YEAR_ENTRY_WIDTH 4 - -#define DEFAULT_MIN_YEAR 1970 - -#define DEFAULT_MAX_YEAR 2037 - -static GtkContainerClass* parent_class; - -static void -hildon_date_editor_class_init (HildonDateEditorClass *editor_class); - -static void -hildon_date_editor_init (HildonDateEditor *editor); - -static gboolean -hildon_date_editor_icon_press (GtkWidget *widget, - gpointer data); - -static gboolean -hildon_date_editor_released (GtkWidget *widget, - gpointer data); - -static gboolean -hildon_date_editor_keypress (GtkWidget *widget, - GdkEventKey *event, - gpointer data); - -static gboolean -hildon_date_editor_keyrelease (GtkWidget *widget, - GdkEventKey *event, - gpointer data); -static gboolean -hildon_date_editor_clicked (GtkWidget *widget, - gpointer data); - -static gint -hildon_date_editor_entry_validate (GtkWidget *widget, - gpointer data); - -static void -hildon_date_editor_entry_changed (GtkEditable *widget, - gpointer data); - -static gboolean -hildon_date_editor_entry_focus_out (GtkWidget *widget, - GdkEventFocus *event, - gpointer data); - -static gboolean -hildon_date_editor_date_error (HildonDateEditor *editor, - HildonDateTimeError type); - -static gboolean -hildon_date_editor_entry_focus_in (GtkWidget *widget, - GdkEventFocus *event, - gpointer data); - -static void -hildon_date_editor_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void -hildon_date_editor_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void -hildon_child_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void -hildon_date_editor_destroy (GtkObject *self); - -static void -hildon_date_editor_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static void -hildon_date_editor_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static gboolean -hildon_date_editor_focus (GtkWidget *widget, - GtkDirectionType direction); -static gboolean -hildon_date_editor_entry_select_all (GtkWidget *widget); - -/* Property indices */ -enum -{ - PROP_0, - PROP_DAY, - PROP_MONTH, - PROP_YEAR, - PROP_MIN_YEAR, - PROP_MAX_YEAR -}; - -enum -{ - DATE_ERROR, - LAST_SIGNAL -}; - -static guint date_editor_signals[LAST_SIGNAL] = { 0 }; - -/** - * hildon_date_editor_get_type: - * - * Initializes and returns the type of a hildon date editor. - * - * Returns: GType of #HildonDateEditor - */ -GType G_GNUC_CONST -hildon_date_editor_get_type (void) -{ - static GType editor_type = 0; - - if (! editor_type) { - static const GTypeInfo editor_info = { - sizeof (HildonDateEditorClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_date_editor_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonDateEditor), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_date_editor_init, - }; - editor_type = g_type_register_static (GTK_TYPE_CONTAINER, - "HildonDateEditor", - &editor_info, 0); - } - - return editor_type; -} - -static void -hildon_date_editor_class_init (HildonDateEditorClass *editor_class) -{ - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (editor_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (editor_class); - GObjectClass *gobject_class = G_OBJECT_CLASS (editor_class); - - parent_class = g_type_class_peek_parent (editor_class); - - g_type_class_add_private (editor_class, sizeof (HildonDateEditorPrivate)); - - gobject_class->set_property = hildon_date_editor_set_property; - gobject_class->get_property = hildon_date_editor_get_property; - widget_class->size_request = hildon_date_editor_size_request; - widget_class->size_allocate = hildon_date_editor_size_allocate; - widget_class->focus = hildon_date_editor_focus; - - container_class->forall = hildon_child_forall; - GTK_OBJECT_CLASS(editor_class)->destroy = hildon_date_editor_destroy; - - editor_class->date_error = (gpointer) hildon_date_editor_date_error; - - date_editor_signals[DATE_ERROR] = - g_signal_new ("date-error", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HildonDateEditorClass, date_error), - g_signal_accumulator_true_handled, NULL, - _hildon_marshal_BOOLEAN__ENUM, - G_TYPE_BOOLEAN, 1, HILDON_TYPE_DATE_TIME_ERROR); - - /** - * HildonDateEditor:year: - * - * Current year. - */ - g_object_class_install_property (gobject_class, PROP_YEAR, - g_param_spec_uint ("year", - "Current year", - "Current year", - 1, 10000, - 2007, - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - /** - * HildonDateEditor:month: - * - * Current month. - */ - g_object_class_install_property (gobject_class, PROP_MONTH, - g_param_spec_uint ("month", - "Current month", - "Current month", - 1, 12, - 1, - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - /** - * HildonDateEditor:day: - * - * Current day. - */ - g_object_class_install_property (gobject_class, PROP_DAY, - g_param_spec_uint ("day", - "Current day", - "Current day", - 1, 31, - 1, - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - /** - * HildonDateEditor:min-year: - * - * Minimum valid year. - */ - g_object_class_install_property (gobject_class, PROP_MIN_YEAR, - g_param_spec_uint ("min-year", - "Minimum valid year", - "Minimum valid year", - 1, 10000, - DEFAULT_MIN_YEAR, - G_PARAM_READWRITE)); - - /** - * HildonDateEditor:max-year: - * - * Maximum valid year. - */ - g_object_class_install_property (gobject_class, PROP_MAX_YEAR, - g_param_spec_uint ("max-year", - "Maximum valid year", - "Maximum valid year", - 1, 10000, - DEFAULT_MAX_YEAR, - G_PARAM_READWRITE)); -} - -/* Forces setting of the icon to certain state. Used initially - and from the actual setter function */ -static void -real_set_calendar_icon_state (HildonDateEditorPrivate *priv, - gboolean pressed) -{ - g_assert (priv); - - gtk_image_set_from_icon_name (GTK_IMAGE (priv->calendar_icon), - "widgets_date_editor", HILDON_ICON_SIZE_SMALL); - - priv->calendar_icon_pressed = pressed; -} - -/* Sets the icon to given state (normal/pressed). Returns - info if the state actually changed. */ -static gboolean -hildon_date_editor_set_calendar_icon_state (HildonDateEditor *editor, - gboolean pressed) -{ - HildonDateEditorPrivate *priv; - - g_assert (HILDON_IS_DATE_EDITOR (editor)); - - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (pressed != priv->calendar_icon_pressed) { - real_set_calendar_icon_state (priv, pressed); - return TRUE; - } - - return FALSE; -} - -/* Packing day, month and year entries depend on locale settings - We find out the order and all separators by converting a known - date to default format and inspecting the result string */ -static void -apply_locale_field_order (HildonDateEditorPrivate *priv) -{ - GDate locale_test_date; - GtkWidget *delim; - gchar buffer[256]; - gchar *iter, *delim_text; - - g_date_set_dmy (&locale_test_date, 1, 2, 1970); - (void) g_date_strftime (buffer, sizeof (buffer), "%x", &locale_test_date); - iter = buffer; - - while (*iter) - { - gchar *endp; - unsigned long value; - - /* Try to convert the current location into number. */ - value = strtoul (iter, &endp, 10); - - /* If the conversion didn't progress or the detected value was - unknown (we used a fixed date, you remember), we treat - current position as a literal */ - switch (value) - { - case 1: - gtk_box_pack_start (GTK_BOX (priv->d_box_date), - priv->d_entry, FALSE, FALSE, 0); - break; - - case 2: - gtk_box_pack_start (GTK_BOX (priv->d_box_date), - priv->m_entry, FALSE, FALSE, 0); - break; - - case 70: /* %x format uses only 2 numbers for some locales */ - case 1970: - gtk_box_pack_start (GTK_BOX (priv->d_box_date), - priv->y_entry, FALSE, FALSE, 0); - break; - - default: - /* All non-number characters starting from current position - form the delimeter */ - for (endp = iter; *endp; endp++) - if (g_ascii_isdigit (*endp)) - break; - - /* Now endp points one place past the delimeter text */ - delim_text = g_strndup (iter, endp - iter); - delim = gtk_label_new (delim_text); - gtk_box_pack_start (GTK_BOX (priv->d_box_date), - delim, FALSE, FALSE, 0); - - priv->delims = g_list_append (priv->delims, delim); - g_free(delim_text); - - break; - }; - - iter = endp; - } -} - -static void -hildon_date_editor_init (HildonDateEditor *editor) -{ - HildonDateEditorPrivate *priv; - GDate cur_date; - - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - GTK_WIDGET_SET_FLAGS (GTK_WIDGET (editor), GTK_NO_WINDOW); - - gtk_widget_push_composite_child (); - - /* initialize values */ - g_date_clear (&cur_date, 1); - g_date_set_time (&cur_date, time (NULL)); - - priv->day = g_date_get_day (&cur_date); - priv->month = g_date_get_month (&cur_date); - priv->year = g_date_get_year (&cur_date); - priv->min_year = DEFAULT_MIN_YEAR; - priv->max_year = DEFAULT_MAX_YEAR; - - /* make widgets */ - priv->frame = gtk_frame_new (NULL); - gtk_container_set_border_width (GTK_CONTAINER (priv->frame), 0); - - priv->d_entry = gtk_entry_new (); - priv->m_entry = gtk_entry_new (); - priv->y_entry = gtk_entry_new (); - -#ifdef MAEMO_GTK - g_object_set (G_OBJECT(priv->d_entry), "hildon-input-mode", - HILDON_GTK_INPUT_MODE_NUMERIC, NULL); - g_object_set (G_OBJECT(priv->m_entry), "hildon-input-mode", - HILDON_GTK_INPUT_MODE_NUMERIC, NULL); - g_object_set (G_OBJECT(priv->y_entry), "hildon-input-mode", - HILDON_GTK_INPUT_MODE_NUMERIC, NULL); -#endif - - /* set entry look */ - gtk_entry_set_width_chars (GTK_ENTRY (priv->d_entry), DAY_ENTRY_WIDTH); - gtk_entry_set_width_chars (GTK_ENTRY (priv->m_entry), MONTH_ENTRY_WIDTH); - gtk_entry_set_width_chars (GTK_ENTRY (priv->y_entry), YEAR_ENTRY_WIDTH); - - gtk_entry_set_max_length (GTK_ENTRY (priv->d_entry), DAY_ENTRY_WIDTH); - gtk_entry_set_max_length (GTK_ENTRY (priv->m_entry), MONTH_ENTRY_WIDTH); - gtk_entry_set_max_length (GTK_ENTRY (priv->y_entry), YEAR_ENTRY_WIDTH); - - gtk_entry_set_has_frame (GTK_ENTRY (priv->d_entry), FALSE); - gtk_entry_set_has_frame (GTK_ENTRY (priv->m_entry), FALSE); - gtk_entry_set_has_frame (GTK_ENTRY (priv->y_entry), FALSE); - - gtk_widget_set_composite_name (priv->d_entry, "day_entry"); - gtk_widget_set_composite_name (priv->m_entry, "month_entry"); - gtk_widget_set_composite_name (priv->y_entry, "year_entry"); - - priv->d_box_date = gtk_hbox_new (FALSE, 0); - - priv->d_button_image = gtk_button_new (); - priv->calendar_icon = gtk_image_new (); - real_set_calendar_icon_state (priv, FALSE); - GTK_WIDGET_UNSET_FLAGS (priv->d_button_image, GTK_CAN_FOCUS | GTK_CAN_DEFAULT); - - apply_locale_field_order (priv); - - gtk_container_add (GTK_CONTAINER (priv->frame), priv->d_box_date); - gtk_container_add (GTK_CONTAINER (priv->d_button_image), priv->calendar_icon); - gtk_button_set_relief (GTK_BUTTON (priv->d_button_image), GTK_RELIEF_NONE); - gtk_button_set_focus_on_click (GTK_BUTTON (priv->d_button_image), FALSE); - - gtk_widget_set_parent (priv->frame, GTK_WIDGET (editor)); - gtk_widget_set_parent (priv->d_button_image, GTK_WIDGET (editor)); - gtk_widget_show_all (priv->frame); - gtk_widget_show_all (priv->d_button_image); - - /* image button signal connects */ - g_signal_connect (GTK_OBJECT (priv->d_button_image), "pressed", - G_CALLBACK (hildon_date_editor_icon_press), editor); - g_signal_connect (GTK_OBJECT (priv->d_button_image), "released", - G_CALLBACK (hildon_date_editor_released), editor); - g_signal_connect (GTK_OBJECT (priv->d_button_image), "clicked", - G_CALLBACK (hildon_date_editor_clicked), editor); - g_signal_connect (GTK_OBJECT (priv->d_button_image), "key_press_event", - G_CALLBACK (hildon_date_editor_keypress), editor); - - /* entry signal connects */ - g_signal_connect (GTK_OBJECT (priv->d_entry), "focus-in-event", - G_CALLBACK (hildon_date_editor_entry_focus_in), editor); - - g_signal_connect (GTK_OBJECT (priv->m_entry), "focus-in-event", - G_CALLBACK (hildon_date_editor_entry_focus_in), editor); - - g_signal_connect (GTK_OBJECT (priv->y_entry), "focus-in-event", - G_CALLBACK (hildon_date_editor_entry_focus_in), editor); - - g_signal_connect (GTK_OBJECT (priv->d_entry), "focus-out-event", - G_CALLBACK (hildon_date_editor_entry_focus_out), editor); - - g_signal_connect (GTK_OBJECT (priv->m_entry), "focus-out-event", - G_CALLBACK (hildon_date_editor_entry_focus_out), editor); - - g_signal_connect (GTK_OBJECT (priv->y_entry), "focus-out-event", - G_CALLBACK (hildon_date_editor_entry_focus_out), editor); - - g_signal_connect (GTK_OBJECT (priv->d_entry), "key-press-event", - G_CALLBACK (hildon_date_editor_keypress), editor); - - g_signal_connect (GTK_OBJECT (priv->m_entry), "key-press-event", - G_CALLBACK (hildon_date_editor_keypress), editor); - - g_signal_connect (GTK_OBJECT (priv->y_entry), "key-press-event", - G_CALLBACK (hildon_date_editor_keypress), editor); - - g_signal_connect (GTK_OBJECT (priv->d_entry), "key-release-event", - G_CALLBACK (hildon_date_editor_keyrelease), editor); - - g_signal_connect(GTK_OBJECT(priv->m_entry), "key-release-event", - G_CALLBACK(hildon_date_editor_keyrelease), editor); - - g_signal_connect (GTK_OBJECT (priv->y_entry), "key-release-event", - G_CALLBACK (hildon_date_editor_keyrelease), editor); - - hildon_date_editor_set_date (editor, priv->year, priv->month, priv->day); - - g_signal_connect (GTK_OBJECT (priv->d_entry), "changed", - G_CALLBACK (hildon_date_editor_entry_changed), editor); - - g_signal_connect (GTK_OBJECT (priv->m_entry), "changed", - G_CALLBACK (hildon_date_editor_entry_changed), editor); - - g_signal_connect (GTK_OBJECT (priv->y_entry), "changed", - G_CALLBACK (hildon_date_editor_entry_changed), editor); - - gtk_widget_pop_composite_child (); -} - -static void -hildon_date_editor_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonDateEditor *editor = HILDON_DATE_EDITOR (object); - HildonDateEditorPrivate *priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - gint val; - - g_assert (priv); - - switch (param_id) - { - case PROP_YEAR: - hildon_date_editor_set_year (editor, g_value_get_uint (value)); - break; - - case PROP_MONTH: - hildon_date_editor_set_month (editor, g_value_get_uint (value)); - break; - - case PROP_DAY: - hildon_date_editor_set_day (editor, g_value_get_uint (value)); - break; - - case PROP_MIN_YEAR: - val = g_value_get_uint (value); - priv->min_year = val; - /* Clamp current year */ - if (hildon_date_editor_get_year (editor) < priv->min_year) - hildon_date_editor_set_year (editor, priv->min_year); - break; - - case PROP_MAX_YEAR: - val = g_value_get_uint (value); - priv->max_year = val; - /* Clamp current year */ - if (hildon_date_editor_get_year (editor) > priv->max_year) - hildon_date_editor_set_year (editor, priv->max_year); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -hildon_date_editor_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - HildonDateEditor *editor = HILDON_DATE_EDITOR (object); - HildonDateEditorPrivate *priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - - switch (param_id) - { - case PROP_YEAR: - g_value_set_uint (value, hildon_date_editor_get_year (editor)); - break; - - case PROP_MONTH: - g_value_set_uint (value, hildon_date_editor_get_month (editor)); - break; - - case PROP_DAY: - g_value_set_uint (value, hildon_date_editor_get_day (editor)); - break; - - case PROP_MIN_YEAR: - g_value_set_uint (value, priv->min_year); - break; - - case PROP_MAX_YEAR: - g_value_set_uint (value, priv->max_year); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); - break; - } -} - -static void -hildon_child_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - HildonDateEditor *editor; - HildonDateEditorPrivate *priv; - - g_assert (HILDON_IS_DATE_EDITOR (container)); - g_assert (callback); - - editor = HILDON_DATE_EDITOR (container); - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (include_internals) { - (*callback) (priv->frame, callback_data); - (*callback) (priv->d_button_image, callback_data); - } -} - -static void -hildon_date_editor_destroy (GtkObject *self) -{ - HildonDateEditorPrivate *priv; - - priv = HILDON_DATE_EDITOR_GET_PRIVATE (self); - g_assert (priv); - - if (priv->frame) { - gtk_widget_unparent (priv->frame); - priv->frame = NULL; - } - if (priv->d_button_image) { - gtk_widget_unparent (priv->d_button_image); - priv->d_button_image = NULL; - } - if (priv->delims) { - g_list_free (priv->delims); - priv->delims = NULL; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - GTK_OBJECT_CLASS (parent_class)->destroy (self); -} - -/** - * hildon_date_editor_new: - * - * Creates a new date editor. The current system date - * is shown in the editor. - * - * Returns: pointer to a new @HildonDateEditor widget. - */ -GtkWidget* -hildon_date_editor_new (void) -{ - return (GtkWidget *) g_object_new (HILDON_TYPE_DATE_EDITOR, NULL); -} - -/** - * hildon_date_editor_set_date: - * @date: the @HildonDateEditor widget - * @year: year - * @month: month - * @day: day - * - * Sets the date shown in the editor. - */ -void -hildon_date_editor_set_date (HildonDateEditor *editor, - guint year, - guint month, - guint day) -{ - HildonDateEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_DATE_EDITOR (editor)); - - /* This function cannot be implemented by calling - component setters, since applying the individual - values one by one can make the date temporarily - invalid (depending on what the previous values were), - which in turn causes that the desired date - is not set (even though it's valid). We must set all the - components at one go and not try to do any validation etc - there in between. */ - - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (g_date_valid_dmy (day, month, year)) - { - GDate date; - gchar buffer[256]; - - priv->year = year; - priv->month = month; - priv->day = day; - - g_date_set_dmy (&date, day, month, year); - - /* We apply the new values, but do not want automatic focus move - etc to take place */ - g_snprintf (buffer, sizeof (buffer), "%04d", year); - g_signal_handlers_block_by_func (priv->y_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - gtk_entry_set_text (GTK_ENTRY (priv->y_entry), buffer); - g_signal_handlers_unblock_by_func (priv->y_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - - g_date_strftime (buffer, sizeof (buffer), "%m", &date); - g_signal_handlers_block_by_func (priv->m_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - gtk_entry_set_text (GTK_ENTRY (priv->m_entry), buffer); - g_signal_handlers_unblock_by_func (priv->m_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - - g_date_strftime (buffer, sizeof (buffer), "%d", &date); - g_signal_handlers_block_by_func (priv->d_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - gtk_entry_set_text (GTK_ENTRY (priv->d_entry), buffer); - g_signal_handlers_unblock_by_func (priv->d_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - - g_object_notify (G_OBJECT (editor), "year"); - g_object_notify (G_OBJECT (editor), "month"); - g_object_notify (G_OBJECT (editor), "day"); - } -} - -/** - * hildon_date_editor_get_date: - * @date: the @HildonDateEditor widget - * @year: a pointer to store the selected year - * @month: a pointer to store the selected month - * @day: a pointer to store the selected day - * - * Gets the date selected in @date. - * You can pass %NULL in any of the pointers if - * you're not interested in obtaining a particular field. - * - */ -void -hildon_date_editor_get_date (HildonDateEditor *date, - guint *year, - guint *month, - guint *day) -{ - HildonDateEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_DATE_EDITOR (date)); - - priv = HILDON_DATE_EDITOR_GET_PRIVATE (date); - - /* FIXME: The role of priv->{day,month,year} members vs. entry contents - is unclear. They do not neccesarily match and still the texts are - used as return values and members for some internal validation!! - At least a partly reason is to allow empty text to become - 0 return value, while members are restricted to valid ranges?! - However, if we change the current way, we are likely to break - some applications if they rely on some specific way how this - widget currently handles empty values and temporarily invalid values. - - The key issue is this: What should the _get methods return while - user is editing a field and the result is incomplete. The - partial result? The last good result? If we return partial result - we also need a way to inform if the date is not valid. Current - implementation is some kind of hybrid of these two... - - for example: - hildon_date_editor_set_day(editor, hildon_date_editor_get_day(editor)); - - easily fails, since set_day tries to force validity while get_day - doesn't do that. - - Proposal: Always return the same values that are shown in the - fields. We add a separate flag (Or use GDate) to - indicate if the current date is valid. This would allow - setters to make the date invalid as well. */ - - if (year != NULL) - *year = /*priv->year;*/ - (guint) atoi (gtk_entry_get_text (GTK_ENTRY (priv->y_entry))); - if (month != NULL) - *month = /*priv->month;*/ - (guint) atoi (gtk_entry_get_text (GTK_ENTRY (priv->m_entry))); - if (day != NULL) - *day = /*priv->day;*/ - (guint) atoi (gtk_entry_get_text (GTK_ENTRY (priv->d_entry))); -} - -/* icon button press event */ -static gboolean -hildon_date_editor_icon_press (GtkWidget *widget, - gpointer data) -{ - g_assert (GTK_IS_WIDGET (widget)); - g_assert (HILDON_IS_DATE_EDITOR (data)); - - hildon_date_editor_set_calendar_icon_state (HILDON_DATE_EDITOR (data), TRUE); - - return FALSE; -} - -static gboolean -hildon_date_editor_entry_focus_in (GtkWidget *widget, - GdkEventFocus *event, - gpointer data) -{ - gdk_threads_add_idle ((GSourceFunc) hildon_date_editor_entry_select_all, GTK_ENTRY (widget)); - - return FALSE; -} - - -static void -popup_calendar_dialog (HildonDateEditor *ed) -{ - guint y = 0, m = 0, d = 0; - GtkWidget *popup; - GtkWidget *parent; - guint result; - GValue val = {0, }; - - hildon_date_editor_get_date (ed, &y, &m, &d); - - parent = gtk_widget_get_ancestor (GTK_WIDGET (ed), GTK_TYPE_WINDOW); - popup = hildon_calendar_popup_new (GTK_WINDOW (parent), y, m, d); - - g_value_init (&val, G_TYPE_INT); - /* Set max/min year in calendar popup to date editor values */ - g_object_get_property (G_OBJECT (ed), "min-year", &val); - g_object_set_property (G_OBJECT (popup), "min-year", &val); - g_object_get_property (G_OBJECT (ed), "max-year", &val); - g_object_set_property (G_OBJECT (popup), "max-year", &val); - - /* Pop up calendar */ - result = gtk_dialog_run (GTK_DIALOG (popup)); - switch (result) { - case GTK_RESPONSE_OK: - case GTK_RESPONSE_ACCEPT: - hildon_calendar_popup_get_date (HILDON_CALENDAR_POPUP (popup), &y, - &m, &d); - hildon_date_editor_set_date (ed, y, m, d); - } - - gtk_widget_destroy (popup); -} - -/* button released */ -static gboolean -hildon_date_editor_released (GtkWidget *widget, - gpointer data) -{ - HildonDateEditor *ed; - - g_assert (GTK_IS_WIDGET (widget)); - g_assert (HILDON_IS_DATE_EDITOR (data)); - - ed = HILDON_DATE_EDITOR (data); - - /* restores the icon state. The clicked cycle raises the dialog */ - hildon_date_editor_set_calendar_icon_state (ed, FALSE); - - return FALSE; -} - -/* button released */ -static gboolean -hildon_date_editor_clicked (GtkWidget *widget, - gpointer data) -{ - HildonDateEditor *ed; - - g_assert (GTK_IS_WIDGET (widget)); - g_assert (HILDON_IS_DATE_EDITOR (data)); - - ed = HILDON_DATE_EDITOR (data); - - /* restores the non-clicked button state and raises the dialog */ - hildon_date_editor_set_calendar_icon_state (ed, FALSE); - popup_calendar_dialog (ed); - - return FALSE; -} - -/* This is called whenever some editor filed loses the focus and - when the all of the fields are filled. - Earlier this was called whenever an entry changed */ -/* FIXME: Validation on focus_out is broken by concept */ -static gint -hildon_date_editor_entry_validate (GtkWidget *widget, - gpointer data) -{ - HildonDateEditor *ed; - HildonDateEditorPrivate *priv; - gint d, m, y, max_days; - gboolean r; /* temp return values for signals */ - const gchar *text; - gint error_code = HILDON_DATE_TIME_ERROR_NO_ERROR; - - g_assert (HILDON_IS_DATE_EDITOR (data)); - g_assert (GTK_IS_ENTRY (widget)); - - ed = HILDON_DATE_EDITOR (data); - priv = HILDON_DATE_EDITOR_GET_PRIVATE (ed); - g_assert (priv); - - if (priv->skip_validation) - return error_code; - - /*check if the calling entry is empty*/ - text = gtk_entry_get_text (GTK_ENTRY (widget)); - if(text == NULL || text[0] == 0) - { - if (widget == priv->d_entry) - g_signal_emit (ed, date_editor_signals[DATE_ERROR], 0, HILDON_DATE_TIME_ERROR_EMPTY_DAY, &r); - else if(widget == priv->m_entry) - g_signal_emit (ed, date_editor_signals[DATE_ERROR], 0, HILDON_DATE_TIME_ERROR_EMPTY_MONTH, &r); - else - g_signal_emit (ed, date_editor_signals[DATE_ERROR], 0, HILDON_DATE_TIME_ERROR_EMPTY_YEAR, &r); - - /* restore empty entry to safe value */ - hildon_date_editor_set_date (ed, priv->year, priv->month, priv->day); - return error_code; - } - - /* Ok, we now check validity. Some fields can be empty */ - text = gtk_entry_get_text (GTK_ENTRY (priv->d_entry)); - if (text == NULL || text[0] == 0) return error_code; - d = atoi (text); - text = gtk_entry_get_text (GTK_ENTRY (priv->m_entry)); - if (text == NULL || text[0] == 0) return error_code; - m = atoi (text); - text = gtk_entry_get_text (GTK_ENTRY (priv->y_entry)); - if (text == NULL || text[0] == 0) return error_code; - y = atoi (text); - - /* Did it actually change? */ - if (d != priv->day || m != priv->month || y != priv->year) - { - /* We could/should use hildon_date_editor_set_year and such functions - * to set the date, instead of use gtk_entry_set_text, and then change - * the priv member but hildon_date_editor_set_year and such functions - * check if the date is valid, we do want to do date validation check - * here according to spec */ - - /* Validate month */ - if (widget == priv->m_entry) { - if (m < 1) { - error_code = HILDON_DATE_TIME_ERROR_MIN_MONTH; - m = 1; - } - else if (m > 12) { - error_code = HILDON_DATE_TIME_ERROR_MAX_MONTH; - m = 12; - } - } - - /* Validate year */ - if(widget == priv->y_entry) { - if (y < priv->min_year) { - error_code = HILDON_DATE_TIME_ERROR_MIN_YEAR; - y = priv->min_year; - } - else if (y > priv->max_year) { - error_code = HILDON_DATE_TIME_ERROR_MAX_YEAR; - y = priv->max_year; - } - } - - /* Validate day. We have to do this in every case, since - changing month or year can make the day number to be invalid */ - max_days = g_date_get_days_in_month (m,y); - if(d < 1) { - error_code = HILDON_DATE_TIME_ERROR_MIN_DAY; - d = 1; - } - else if (d > max_days) { - if (d > 31) { - error_code = HILDON_DATE_TIME_ERROR_MAX_DAY; - d = max_days; - } - else { /* the date does not exist (is invalid) */ - error_code = HILDON_DATE_TIME_ERROR_INVALID_DATE; - /* check what was changed and restore previous value */ - if (widget == priv->y_entry) - y = priv->year; - else if (widget == priv->m_entry) - m = priv->month; - else - d = priv->day; - } - } - - if (error_code != HILDON_DATE_TIME_ERROR_NO_ERROR) - { - g_signal_emit (ed, date_editor_signals[DATE_ERROR], 0, error_code, &r); - - gdk_threads_add_idle ((GSourceFunc) hildon_date_editor_entry_select_all, widget); - } - } - - /* Fix and reformat the date after error signal is processed. - reformatting can be needed even in a such case that numerical - values of the date components are the same as earlier. */ - hildon_date_editor_set_date (ed, y, m, d); - return error_code; -} - -/* Idle callback */ -static gboolean -hildon_date_editor_entry_select_all (GtkWidget *widget) -{ - gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1); - return FALSE; -} - -/* When entry becomes full, we move the focus to the next field. - If we are on the last field, the whole contents are validated. */ -static void -hildon_date_editor_entry_changed (GtkEditable *ed, - gpointer data) -{ - GtkEntry *entry; - gint error_code; - - HildonDateEditorPrivate *priv; - priv = HILDON_DATE_EDITOR_GET_PRIVATE (HILDON_DATE_EDITOR (data)); - - g_assert (GTK_IS_ENTRY (ed)); - g_assert (HILDON_IS_DATE_EDITOR (data)); - g_assert (priv); - - entry = GTK_ENTRY (ed); - - /* If day entry is full, move to next entry or validate */ - if (g_utf8_strlen (gtk_entry_get_text (entry), -1) == gtk_entry_get_max_length (entry)) - { - error_code = hildon_date_editor_entry_validate (GTK_WIDGET (entry), data); - if (error_code == HILDON_DATE_TIME_ERROR_NO_ERROR) - { - priv->skip_validation = TRUE; - gtk_widget_child_focus (GTK_WIDGET (data), GTK_DIR_RIGHT); - } - } else { - priv->skip_validation = FALSE; - } -} - -static gboolean -hildon_date_editor_keyrelease (GtkWidget *widget, - GdkEventKey *event, - gpointer data) -{ - HildonDateEditor *ed; - HildonDateEditorPrivate *priv; - - g_return_val_if_fail (data, FALSE); - g_return_val_if_fail (widget, FALSE); - - ed = HILDON_DATE_EDITOR (data); - priv = HILDON_DATE_EDITOR_GET_PRIVATE (ed); - - if (event->keyval == GDK_KP_Enter || - event->keyval == GDK_Return || - event->keyval == GDK_ISO_Enter) { - if (hildon_date_editor_set_calendar_icon_state (ed, FALSE)) - { - popup_calendar_dialog (ed); - return TRUE; - } - } else if (event->keyval == GDK_Escape) - priv->skip_validation = FALSE; - - return FALSE; -} - -/* keyboard handling */ -static gboolean -hildon_date_editor_keypress (GtkWidget *widget, - GdkEventKey *event, - gpointer data) -{ - HildonDateEditor *ed; - HildonDateEditorPrivate *priv; - - g_assert (HILDON_IS_DATE_EDITOR (data)); - g_assert (GTK_IS_ENTRY (widget)); - - ed = HILDON_DATE_EDITOR (data); - - switch (event->keyval) { - case GDK_Return: - case GDK_ISO_Enter: - /* Ignore return value, since we want to handle event at all times. - otherwise vkb would popup when the keyrepeat starts. */ - hildon_date_editor_set_calendar_icon_state (ed, TRUE); - return TRUE; - case GDK_Escape: - priv = HILDON_DATE_EDITOR_GET_PRIVATE (ed); - priv->skip_validation = TRUE; - break; - default: - break; - } - - return FALSE; -} - -static gboolean -hildon_date_editor_entry_focus_out (GtkWidget *widget, - GdkEventFocus *event, - gpointer data) -{ - HildonDateEditor *ed; - HildonDateEditorPrivate *priv; - - g_assert (HILDON_IS_DATE_EDITOR (data)); - - ed = HILDON_DATE_EDITOR (data); - priv = HILDON_DATE_EDITOR_GET_PRIVATE (ed); - g_assert (priv); - - hildon_date_editor_entry_validate (widget, data); - priv->skip_validation = FALSE; - - return FALSE; -} - -static gboolean -hildon_date_editor_date_error (HildonDateEditor *editor, - HildonDateTimeError type) -{ - HildonDateEditorPrivate *priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - switch (type) - { - case HILDON_DATE_TIME_ERROR_MAX_DAY: - hildon_banner_show_informationf (GTK_WIDGET (editor), NULL, _("ckct_ib_maximum_value"), 31); - break; - - case HILDON_DATE_TIME_ERROR_MAX_MONTH: - hildon_banner_show_informationf (GTK_WIDGET (editor), NULL, _("ckct_ib_maximum_value"), 12); - break; - - case HILDON_DATE_TIME_ERROR_MAX_YEAR: - hildon_banner_show_informationf (GTK_WIDGET (editor), NULL, _("ckct_ib_maximum_value"), priv->max_year); - break; - - case HILDON_DATE_TIME_ERROR_MIN_DAY: - case HILDON_DATE_TIME_ERROR_MIN_MONTH: - hildon_banner_show_informationf (GTK_WIDGET (editor), NULL, _("ckct_ib_minimum_value"), 1); - break; - - case HILDON_DATE_TIME_ERROR_MIN_YEAR: - hildon_banner_show_informationf (GTK_WIDGET (editor), NULL, _("ckct_ib_minimum_value"), priv->min_year); - break; - - case HILDON_DATE_TIME_ERROR_EMPTY_DAY: - hildon_banner_show_informationf (GTK_WIDGET (editor), NULL, _("ckct_ib_set_a_value_within_range"), 1, 31); - break; - - case HILDON_DATE_TIME_ERROR_EMPTY_MONTH: - hildon_banner_show_informationf (GTK_WIDGET (editor), NULL, _("ckct_ib_set_a_value_within_range"), 1, 12); - break; - - case HILDON_DATE_TIME_ERROR_EMPTY_YEAR: - hildon_banner_show_informationf (GTK_WIDGET (editor), NULL, _("ckct_ib_set_a_value_within_range"), - priv->min_year, priv->max_year); - break; - - case HILDON_DATE_TIME_ERROR_INVALID_CHAR: - hildon_banner_show_information (GTK_WIDGET (editor), NULL, c_("ckct_ib_illegal_character")); - break; - - case HILDON_DATE_TIME_ERROR_INVALID_DATE: - hildon_banner_show_information (GTK_WIDGET (editor), NULL, _("ckct_ib_date_does_not_exist")); - break; - - default: - /*default error message ?*/ - break; - } - - return TRUE; -} - -static void -hildon_date_editor_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - HildonDateEditor *ed; - HildonDateEditorPrivate *priv; - GtkRequisition f_req, img_req; - - g_assert (GTK_IS_WIDGET (widget)); - g_assert (requisition != NULL); - - ed = HILDON_DATE_EDITOR (widget); - priv = HILDON_DATE_EDITOR_GET_PRIVATE (ed); - g_assert (priv); - - /* Our own children affect our size */ - gtk_widget_size_request (priv->frame, &f_req); - gtk_widget_size_request (priv->d_button_image, &img_req); - - /* calculate our size */ - requisition->width = f_req.width + img_req.width + HILDON_MARGIN_DEFAULT; - - /* FIXME: Fixed size is bad! We should use the maximum of our children, but - doing so would break current pixel specifications, since - the text entry by itself is already 30px tall + then frame takes - something */ - requisition->height = DATE_EDITOR_HEIGHT; -} - -static void -hildon_date_editor_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - HildonDateEditor *ed; - HildonDateEditorPrivate *priv; - GtkAllocation f_alloc, img_alloc; - GtkRequisition req; - GtkRequisition max_req; - GList *iter; - gboolean rtl; - - g_assert (GTK_IS_WIDGET (widget)); - g_assert (allocation != NULL); - - ed = HILDON_DATE_EDITOR (widget); - priv = HILDON_DATE_EDITOR_GET_PRIVATE (ed); - - rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL); - widget->allocation = *allocation; - - gtk_widget_get_child_requisition (widget, &max_req); - - /* Center vertically */ - f_alloc.y = img_alloc.y = allocation->y + - MAX (allocation->height - max_req.height, 0) / 2; - - /* Center horizontally */ - f_alloc.x = img_alloc.x = allocation->x + - MAX (allocation->width - max_req.width, 0) / 2; - - /* calculate allocations */ - if (GTK_WIDGET_VISIBLE (widget)) { - /* allocate frame */ - gtk_widget_get_child_requisition (priv->frame, &req); - - f_alloc.width = req.width; - f_alloc.height = max_req.height; - - /* allocate icon */ - gtk_widget_get_child_requisition (priv->d_button_image, - &req); - - img_alloc.x += f_alloc.width + HILDON_MARGIN_DEFAULT; - img_alloc.width = req.width; - img_alloc.height = max_req.height; - - if (rtl) - { - img_alloc.x = f_alloc.x; - f_alloc.x += img_alloc.width + HILDON_MARGIN_DEFAULT; - } - - if (GTK_WIDGET_VISIBLE (priv->d_button_image)) { - gtk_widget_size_allocate (priv->d_button_image, &img_alloc); - } - - if (GTK_WIDGET_VISIBLE (priv->frame)) { - gtk_widget_size_allocate (priv->frame, &f_alloc); - } - } - - /* FIXME: We really should not alloc delimeters by hand (since they - are not our own children, but we need to force to appear - higher. This ugly hack is needed to compensate the forced - height in size_request. */ - for (iter = priv->delims; iter; iter = iter->next) - { - GtkWidget *delim; - GtkAllocation alloc; - - delim = GTK_WIDGET (iter->data); - alloc = delim->allocation; - alloc.height = max_req.height; - alloc.y = priv->d_entry->allocation.y - 2; - - gtk_widget_size_allocate (delim, &alloc); - } -} - -static gboolean -hildon_date_editor_focus (GtkWidget *widget, - GtkDirectionType direction) -{ - gboolean retval; - GtkDirectionType effective_direction; - - g_assert (HILDON_IS_DATE_EDITOR (widget)); - - retval = hildon_private_composite_focus (widget, direction, &effective_direction); - - if (retval == TRUE) - return GTK_WIDGET_CLASS (parent_class)->focus (widget, effective_direction); - else - return FALSE; -} - -/** - * hildon_date_editor_set_year: - * @editor: the @HildonDateEditor widget - * @year: year - * - * Sets the year shown in the editor. - * - * Returns: TRUE if the year is valid and has been set. - */ -gboolean -hildon_date_editor_set_year (HildonDateEditor *editor, - guint year) -{ - HildonDateEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_DATE_EDITOR (editor), FALSE); - - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (g_date_valid_dmy (priv->day, priv->month, year)) - { - gchar buffer[256]; - priv->year = year; - - g_snprintf (buffer, sizeof (buffer), "%04d", year); - - /* We apply the new day, but do not want automatic focus move - etc to take place */ - g_signal_handlers_block_by_func (priv->y_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - gtk_entry_set_text (GTK_ENTRY (priv->y_entry), buffer); - g_signal_handlers_unblock_by_func (priv->y_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - - g_object_notify (G_OBJECT(editor), "year"); - return TRUE; - } - - return FALSE; -} - -/** - * hildon_date_editor_set_month: - * @editor: the @HildonDateEditor widget - * @month: month - * - * Sets the month shown in the editor. - * - * Returns: TRUE if the month is valid and has been set. - */ -gboolean -hildon_date_editor_set_month (HildonDateEditor *editor, - guint month) -{ - HildonDateEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_DATE_EDITOR (editor), FALSE); - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (g_date_valid_dmy (priv->day, month, priv->year)) - { - GDate date; - gchar buffer[256]; - - priv->month = month; - g_date_set_dmy (&date, priv->day, month, priv->year); - g_date_strftime (buffer, sizeof(buffer), "%m", &date); - - /* We apply the new day, but do not want automatic focus move - etc to take place */ - g_signal_handlers_block_by_func (priv->m_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - gtk_entry_set_text (GTK_ENTRY (priv->m_entry), buffer); - g_signal_handlers_unblock_by_func (priv->m_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - - g_object_notify (G_OBJECT (editor), "month"); - return TRUE; - } - return FALSE; -} - -/** - * hildon_date_editor_set_day: - * @editor: the @HildonDateEditor widget - * @day: day - * - * Sets the day shown in the editor. - * - * Returns: TRUE if the day is valid and has been set. - */ -gboolean -hildon_date_editor_set_day (HildonDateEditor *editor, - guint day) -{ - HildonDateEditorPrivate *priv; - - g_return_val_if_fail (HILDON_IS_DATE_EDITOR (editor), FALSE); - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (g_date_valid_dmy (day, priv->month, priv->year)) - { - GDate date; - gchar buffer[256]; - - priv->day = day; - g_date_set_dmy (&date, day, priv->month, priv->year); - g_date_strftime (buffer, sizeof (buffer), "%d", &date); - - /* We apply the new day, but do not want automatic focus move - etc to take place */ - g_signal_handlers_block_by_func (priv->d_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - gtk_entry_set_text (GTK_ENTRY (priv->d_entry), buffer); - g_signal_handlers_unblock_by_func (priv->d_entry, - (gpointer) hildon_date_editor_entry_changed, editor); - - g_object_notify (G_OBJECT(editor), "day"); - return TRUE; - } - return FALSE; -} - -/** - * hildon_date_editor_get_year: - * @editor: the #HildonDateEditor widget - * - * Gets the year shown in the editor. - * - * Returns: the current year shown in the editor. - */ -guint -hildon_date_editor_get_year (HildonDateEditor *editor) -{ - HildonDateEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_DATE_EDITOR(editor), 0); - - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - return (guint) atoi (gtk_entry_get_text (GTK_ENTRY (priv->y_entry))); -} - -/** - * hildon_date_editor_get_month: - * @editor: the @HildonDateEditor widget - * - * Gets the month shown in the editor. - * - * Returns: the current month shown in the editor. - */ -guint -hildon_date_editor_get_month (HildonDateEditor *editor) -{ - HildonDateEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_DATE_EDITOR (editor), 0); - - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - return (guint) atoi (gtk_entry_get_text (GTK_ENTRY (priv->m_entry))); -} - -/** - * hildon_date_editor_get_day: - * @editor: the @HildonDateEditor widget - * - * Gets the day shown in the editor. - * - * Returns: the current day shown in the editor - */ -guint -hildon_date_editor_get_day (HildonDateEditor *editor) -{ - HildonDateEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_DATE_EDITOR (editor), 0); - - priv = HILDON_DATE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - return (guint) atoi (gtk_entry_get_text (GTK_ENTRY (priv->d_entry))); -} - diff --git a/hildon/hildon-date-editor.h b/hildon/hildon-date-editor.h deleted file mode 100644 index ad6be83..0000000 --- a/hildon/hildon-date-editor.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_DATE_EDITOR_H__ -#define __HILDON_DATE_EDITOR_H__ - -#include <gtk/gtk.h> - -#include "hildon-time-editor.h" - -G_BEGIN_DECLS - -#define HILDON_TYPE_DATE_EDITOR \ - (hildon_date_editor_get_type()) - -#define HILDON_DATE_EDITOR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj,\ - HILDON_TYPE_DATE_EDITOR, HildonDateEditor)) - -#define HILDON_DATE_EDITOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_DATE_EDITOR, HildonDateEditorClass)) - -#define HILDON_IS_DATE_EDITOR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj,\ - HILDON_TYPE_DATE_EDITOR)) - -#define HILDON_IS_DATE_EDITOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass),\ - HILDON_TYPE_DATE_EDITOR)) - -typedef struct _HildonDateEditor HildonDateEditor; - -typedef struct _HildonDateEditorClass HildonDateEditorClass; - - -struct _HildonDateEditor -{ - GtkContainer parent; -}; - -struct _HildonDateEditorClass -{ - GtkContainerClass parent_class; - - gboolean (*date_error) (HildonDateEditor *editor, HildonDateTimeError type); -}; - -GType G_GNUC_CONST -hildon_date_editor_get_type (void); - -GtkWidget* -hildon_date_editor_new (void); - -void -hildon_date_editor_set_date (HildonDateEditor *date, - guint year, - guint month, - guint day); - -void -hildon_date_editor_get_date (HildonDateEditor *date, - guint *year, - guint *month, - guint *day); - -gboolean -hildon_date_editor_set_year (HildonDateEditor *editor, - guint year); - -gboolean -hildon_date_editor_set_month (HildonDateEditor *editor, - guint month); - -gboolean hildon_date_editor_set_day (HildonDateEditor *editor, - guint day); - -guint -hildon_date_editor_get_year (HildonDateEditor *editor); - -guint -hildon_date_editor_get_month (HildonDateEditor *editor); - -guint -hildon_date_editor_get_day (HildonDateEditor *editor); - -G_END_DECLS - -#endif /* __HILDON_DATE_EDITOR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-defines.h b/hildon/hildon-defines.h index f6e251d..30547e8 100644 --- a/hildon/hildon-defines.h +++ b/hildon/hildon-defines.h @@ -119,18 +119,6 @@ G_BEGIN_DECLS */ #define HILDON_ICON_SIZE_XLARGE gtk_icon_size_from_name ("hildon-xlarge") -/* legacy hildon icon sizes, updated for new hildon */ - -/** - * HILDON_ICON_SIZE_TOOLBAR: - * - * #GtkIconSize for toolbar icons. - * - * Deprecated: Use %HILDON_ICON_SIZE_FINGER instead. - */ -#ifndef HILDON_DISABLE_DEPRECATED -#define HILDON_ICON_SIZE_TOOLBAR gtk_icon_size_from_name ("hildon-finger") -#endif /* Actual icon sizes */ /* New sizes */ @@ -197,17 +185,6 @@ G_BEGIN_DECLS */ #define HILDON_ICON_PIXEL_SIZE_XLARGE hildon_get_icon_pixel_size (HILDON_ICON_SIZE_XLARGE) -/* legacy sizes */ -/** - * HILDON_ICON_PIXEL_SIZE_TOOLBAR: - * - * Pixel size for toolbar icons. - * - * Deprecated: Use %HILDON_ICON_PIXEL_SIZE_FINGER instead. - */ -#ifndef HILDON_DISABLE_DEPRECATED -#define HILDON_ICON_PIXEL_SIZE_TOOLBAR hildon_get_icon_pixel_size (HILDON_ICON_SIZE_TOOLBAR) -#endif /* Margins */ /** diff --git a/hildon/hildon-dialog.c b/hildon/hildon-dialog.c deleted file mode 100644 index 1a3977c..0000000 --- a/hildon/hildon-dialog.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2008 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-dialog - * @short_description: A popup window in the Hildon framework. - * @see_also: #HildonCodeDialog, #HildonColorChooserDialog, #HildonFontSelectionDialog, #HildonGetPasswordDialog, #HildonLoginDialog, #HildonSetPasswordDialog, #HildonSortDialog, #HildonWizardDialog - * - * #HildonDialog is a popup window in the - * Hildon framework. It is derived from #GtkDialog and provides additional - * commodities specific to the Hildon framework. - * - * As of hildon 2.2, #HildonDialog has been deprecated in favor of #GtkDialog. - * - * <note> - * <para> - * #HildonDialog has been deprecated since Hildon 2.2 and should not - * be used in newly written code. See - * <link linkend="hildon-migrating-hildon-dialogs">Migrating Hildon Dialogs</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <title>Simple <structname>HildonDialog</structname> usage</title> - * <programlisting> - * void quick_message (gchar *message) - * { - * <!-- --> - * GtkWidget *dialog, *label; - * <!-- --> - * dialog = hildon_dialog_new (); - * label = gtk_label_new (message); - * <!-- --> - * g_signal_connect_swapped (dialog, - * "response", - * G_CALLBACK (gtk_widget_destroy), - * dialog); - * <!-- --> - * gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), - * label); - * gtk_widget_show_all (dialog); - * <!-- --> - * } - * </programlisting> - * </example> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#include "hildon-dialog.h" -#include "hildon-gtk.h" - -G_DEFINE_TYPE (HildonDialog, hildon_dialog, GTK_TYPE_DIALOG); - -static void -hildon_dialog_class_init (HildonDialogClass *dialog_class) -{ -} - -static void -hildon_dialog_init (HildonDialog *self) -{ -} - -/** - * hildon_dialog_new: - * - * Creates a new #HildonDialog widget - * - * Returns: the newly created #HildonDialog - * - * Since: 2.2 - */ -GtkWidget* -hildon_dialog_new (void) -{ - GtkWidget *self = g_object_new (HILDON_TYPE_DIALOG, NULL); - - return self; -} - -/** - * hildon_dialog_new_with_buttons: - * @title: Title of the dialog, or %NULL - * @parent: Transient parent of the dialog, or %NULL - * @flags: from #GtkDialogFlags - * @first_button_text: stock ID or text to go in first button, or %NULL - * @Varargs: response ID for first button, then additional buttons, ending with %NULL - * - * Creates a new #HildonDialog. See gtk_dialog_new_with_buttons() for - * more information. - * - * Return value: a new #HildonDialog - * - * Since: 2.2 - */ -GtkWidget* -hildon_dialog_new_with_buttons (const gchar *title, - GtkWindow *parent, - GtkDialogFlags flags, - const gchar *first_button_text, - ...) -{ - GtkWidget *dialog; - - dialog = g_object_new (HILDON_TYPE_DIALOG, NULL); - - /* This code is copied from gtk_dialog_new_empty(), as it's a - * private function that we cannot use here */ - if (title) - gtk_window_set_title (GTK_WINDOW (dialog), title); - - if (parent) - gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); - - if (flags & GTK_DIALOG_MODAL) - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - - if (flags & GTK_DIALOG_DESTROY_WITH_PARENT) - gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); - - if (flags & GTK_DIALOG_NO_SEPARATOR) - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - - /* This is almost copied from gtk_dialog_add_buttons_valist() */ - if (first_button_text != NULL) { - va_list args; - const gchar *text; - gint response_id; - - va_start (args, first_button_text); - text = first_button_text; - response_id = va_arg (args, gint); - - while (text != NULL) { - hildon_dialog_add_button (HILDON_DIALOG (dialog), text, response_id); - - text = va_arg (args, gchar*); - if (text == NULL) - break; - response_id = va_arg (args, int); - } - va_end (args); - } - - return dialog; -} - -/** - * hildon_dialog_add_button: - * @dialog: a #HildonDialog - * @button_text: text of the button, or stock ID - * @response_id: response ID for the button. - * - * Adds a button to the dialog. Works exactly like - * gtk_dialog_add_button(), the only difference being that the button - * has finger size. - * - * Returns: the button widget that was added - * - * Since: 2.2 - */ -GtkWidget * -hildon_dialog_add_button (HildonDialog *dialog, - const gchar *button_text, - gint response_id) -{ - GtkWidget *button; - button = gtk_dialog_add_button (GTK_DIALOG (dialog), button_text, response_id); - return button; -} - -/** - * hildon_dialog_add_buttons: - * @dialog: a #HildonDialog - * @first_button_text: text of the button, or stock ID - * @Varargs: response ID for first button, then more text-response_id pairs - * - * Adds several buttons to the dialog. Works exactly like - * gtk_dialog_add_buttons(), the only difference being that the - * buttons have finger size. - * - * Since: 2.2 - */ -void -hildon_dialog_add_buttons (HildonDialog *dialog, - const gchar *first_button_text, - ...) -{ - va_list args; - const gchar *text; - gint response_id; - - va_start (args, first_button_text); - text = first_button_text; - response_id = va_arg (args, gint); - - while (text != NULL) { - hildon_dialog_add_button (HILDON_DIALOG (dialog), text, response_id); - - text = va_arg (args, gchar*); - if (text == NULL) - break; - response_id = va_arg (args, int); - } - - va_end (args); -} - diff --git a/hildon/hildon-dialog.h b/hildon/hildon-dialog.h deleted file mode 100644 index 37f0a8a..0000000 --- a/hildon/hildon-dialog.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2008 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_DIALOG_H__ -#define __HILDON_DIALOG_H__ - -#include <gtk/gtk.h> - -#include "hildon-defines.h" - -G_BEGIN_DECLS - -#define HILDON_TYPE_DIALOG \ - (hildon_dialog_get_type ()) - -#define HILDON_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_DIALOG, HildonDialog)) - -#define HILDON_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_DIALOG, HildonDialogClass)) - -#define HILDON_IS_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_DIALOG)) - -#define HILDON_IS_DIALOG_CLASS(klass) \ - (GTK_CHECH_CLASS_TYPE ((klass), HILDON_TYPE_DIALOG)) - -#define HILDON_DIALOG_GET_CLASS(obj) \ - ((HildonDialogClass *) G_OBJECT_GET_CLASS (obj)) - -typedef struct _HildonDialog HildonDialog; - -typedef struct _HildonDialogClass HildonDialogClass; - -struct _HildonDialog -{ - GtkDialog parent; -}; - -struct _HildonDialogClass -{ - GtkDialogClass parent_class; - - /* Padding for future extension */ - void (*_hildon_reserved1)(void); - void (*_hildon_reserved2)(void); - void (*_hildon_reserved3)(void); -}; - -GType G_GNUC_CONST -hildon_dialog_get_type (void); - -GtkWidget* -hildon_dialog_new (void); - -GtkWidget* -hildon_dialog_new_with_buttons (const gchar *title, - GtkWindow *parent, - GtkDialogFlags flags, - const gchar *first_button_text, - ...); - -GtkWidget * -hildon_dialog_add_button (HildonDialog *dialog, - const gchar *button_text, - gint response_id); - -void -hildon_dialog_add_buttons (HildonDialog *dialog, - const gchar *first_button_text, - ...); - -G_END_DECLS - -#endif /* __HILDON_DIALOG_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-entry.c b/hildon/hildon-entry.c index ae2e345..83df493 100644 --- a/hildon/hildon-entry.c +++ b/hildon/hildon-entry.c @@ -45,8 +45,6 @@ * </example> */ -#undef HILDON_DISABLE_DEPRECATED - #include "hildon-entry.h" #include "hildon-enum-types.h" @@ -80,71 +78,6 @@ set_property (GObject *object, } /** - * hildon_entry_set_text: - * @entry: a #HildonEntry - * @text: the new text - * - * Sets the text in @entry to @text, replacing its current contents. - * - * Since: 2.2 - * - * Deprecated: Use gtk_entry_set_text() instead - */ -void -hildon_entry_set_text (HildonEntry *entry, - const gchar *text) -{ - g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL); - gtk_entry_set_text (GTK_ENTRY (entry), text); -} - -/** - * hildon_entry_get_text: - * @entry: a #HildonEntry - * - * Gets the current text in @entry. - * - * Note that the placeholder text (set using - * hildon_gtk_entry_set_placeholder_text()) is never returned. Only - * text set by gtk_entry_set_text() or typed by the user is - * considered. - * - * Returns: the text in @entry. This text must not be modified or - * freed. - * - * Since: 2.2 - * - * Deprecated: Use gtk_entry_get_text() instead - */ -const gchar * -hildon_entry_get_text (HildonEntry *entry) -{ - g_return_val_if_fail (HILDON_IS_ENTRY (entry), NULL); - return gtk_entry_get_text (GTK_ENTRY (entry)); -} - -/** - * hildon_entry_set_placeholder: - * @entry: a #HildonEntry - * @text: the new text - * - * Sets the placeholder text in @entry to @text. - * - * Since: 2.2 - * - * Deprecated: Use hildon_gtk_entry_set_placeholder_text() instead - */ -void -hildon_entry_set_placeholder (HildonEntry *entry, - const gchar *text) -{ - g_return_if_fail (HILDON_IS_ENTRY (entry) && text != NULL); -#ifdef MAEMO_GTK - hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry), text); -#endif -} - -/** * hildon_entry_new: * @size: The size of the entry * diff --git a/hildon/hildon-entry.h b/hildon/hildon-entry.h index 561430a..ac4b2df 100644 --- a/hildon/hildon-entry.h +++ b/hildon/hildon-entry.h @@ -68,19 +68,6 @@ hildon_entry_get_type (void) G_GNUC_CONST; GtkWidget * hildon_entry_new (HildonSizeType size); -#ifndef HILDON_DISABLE_DEPRECATED -void -hildon_entry_set_text (HildonEntry *entry, - const gchar *text); - -const gchar * -hildon_entry_get_text (HildonEntry *entry); - -void -hildon_entry_set_placeholder (HildonEntry *entry, - const gchar *text); -#endif - G_END_DECLS #endif /* __HILDON_ENTRY_H__ */ diff --git a/hildon/hildon-font-selection-dialog-private.h b/hildon/hildon-font-selection-dialog-private.h deleted file mode 100644 index bb0628c..0000000 --- a/hildon/hildon-font-selection-dialog-private.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_FONT_SELECTION_DIALOG_PRIVATE_H__ -#define __HILDON_FONT_SELECTION_DIALOG_PRIVATE_H__ - -G_BEGIN_DECLS - -#define HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_FONT_SELECTION_DIALOG, \ - HildonFontSelectionDialogPrivate)) - -typedef struct _HildonFontSelectionDialogPrivate HildonFontSelectionDialogPrivate; - -struct _HildonFontSelectionDialogPrivate -{ - GtkNotebook *notebook; - - gchar *preview_text; - - /* Tab one */ - GtkWidget *cbx_font_type; - GtkWidget *cbx_font_size; - GtkWidget *font_color_button; - - /* Tab two */ - GtkWidget *chk_bold; - GtkWidget *chk_italic; - GtkWidget *chk_underline; - - /* Tab three */ - GtkWidget *chk_strikethrough; - GtkWidget *cbx_positioning; - - /* Every family */ - PangoFontFamily **families; - gint n_families; - - /* color_set is used to show whether the color is inconsistent - * The handler id is used to block the signal emission - * when we change the color setting */ - gboolean color_set; - - /* font_scaling is the scaling factor applied to font - * scale in the preview dialog */ - gdouble font_scaling; - - gulong color_modified_signal_handler; -}; - -G_END_DECLS - -#endif /* __HILDON_FONT_SELECTION_DIALOG_PRIVATE_H__ */ diff --git a/hildon/hildon-font-selection-dialog.c b/hildon/hildon-font-selection-dialog.c deleted file mode 100644 index f69899b..0000000 --- a/hildon/hildon-font-selection-dialog.c +++ /dev/null @@ -1,1414 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-font-selection-dialog - * @short_description: A widget used to allow users to select a font - * with certain properties. - * - * Font selection can be made using this widget. Users can select font name, - * size, style, etc. Since hildon 2.2, the previously available preview dialog - * has been removed. - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <libintl.h> -#include <stdlib.h> -#include <string.h> - -#include <glib.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-font-selection-dialog.h" -#include "hildon-caption.h" -#include "hildon-color-button.h" -#include "hildon-font-selection-dialog-private.h" -#include "hildon-stock.h" - -/* These are what we use as the standard font sizes, for the size list */ - -static const guint16 font_sizes[] = -{ - 6, 8, 10, 12, 16, 24, 32 -}; - -enum -{ - PROP_0, - PROP_FAMILY, - PROP_FAMILY_SET, - PROP_SIZE, - PROP_SIZE_SET, - PROP_COLOR, - PROP_COLOR_SET, - PROP_BOLD, - PROP_BOLD_SET, - PROP_ITALIC, - PROP_ITALIC_SET, - PROP_UNDERLINE, - PROP_UNDERLINE_SET, - PROP_STRIKETHROUGH, - PROP_STRIKETHROUGH_SET, - PROP_POSITION, - PROP_POSITION_SET, - PROP_PREVIEW_TEXT, - PROP_FONT_SCALING -}; - -/* combo box active row indicator -2--inconsistent, -1--undefined - * please make sure that you use settings_init settings_apply - * and settings_destroy, dont even try to touch this structure - * without using the three above interface functions, of course - * if you know what you are doing, do as you please ;-)*/ -typedef struct -{ - HildonFontSelectionDialog *fsd; /* pointer to our font selection dialog */ - - gint family; /* combo box indicator */ - gint size; /* combo box indicator */ - GdkColor *color; /* free after read the setting */ - gboolean color_inconsist; - gint weight; /* bit mask */ - gint style; /* bit mask */ - gint underline; /* bit mask */ - gint strikethrough; /* bit mask */ - gint position; /* combo box indicator */ - -} HildonFontSelectionDialogSettings; - -#if 0 -static gboolean -hildon_font_selection_dialog_preview_key_press (GtkWidget *widget, - GdkEventKey *event, - gpointer unused); -#endif - -static int -cmp_families (const void *a, - const void *b); -#if 0 -static void -hildon_font_selection_dialog_show_preview (HildonFontSelectionDialog *fontsel); - -static PangoAttrList* -hildon_font_selection_dialog_create_attrlist (HildonFontSelectionDialog *fontsel, - guint start_index, - guint len); -#endif - -static void -hildon_font_selection_dialog_show_available_positionings (HildonFontSelectionDialogPrivate *priv); - -static void -hildon_font_selection_dialog_show_available_fonts (HildonFontSelectionDialog *fontsel); - -static void -hildon_font_selection_dialog_show_available_sizes (HildonFontSelectionDialogPrivate *priv); - -static void -hildon_font_selection_dialog_class_init (HildonFontSelectionDialogClass *klass); - -static void -hildon_font_selection_dialog_init (HildonFontSelectionDialog *fontseldiag); - -static void -hildon_font_selection_dialog_finalize (GObject *object); - -static void -hildon_font_selection_dialog_construct_notebook (HildonFontSelectionDialog *fontsel); - -static void -color_modified_cb (HildonColorButton *button, - GParamSpec *pspec, - gpointer fsd_priv); - -#if 0 -static void -add_preview_text_attr (PangoAttrList *list, - PangoAttribute *attr, - guint start, - guint len); -#endif - -static void -toggle_clicked (GtkButton *button, - gpointer unused); - -static GtkDialogClass* parent_class = NULL; - -#define _(String) dgettext("hildon-libs", String) - -#define SUPERSCRIPT_RISE 3333 - -#define SUBSCRIPT_LOW -3333 - -#define ON_BIT 0x01 - -#define OFF_BIT 0x02 - -/** - * hildon_font_selection_dialog_get_type: - * - * Initializes and returns the type of a hildon font selection dialog - * - * Returns: GType of #HildonFontSelectionDialog - */ -GType G_GNUC_CONST -hildon_font_selection_dialog_get_type (void) -{ - static GType font_selection_dialog_type = 0; - - if (! font_selection_dialog_type) { - static const GTypeInfo fontsel_diag_info = { - sizeof(HildonFontSelectionDialogClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_font_selection_dialog_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(HildonFontSelectionDialog), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_font_selection_dialog_init, - }; - - font_selection_dialog_type = - g_type_register_static (GTK_TYPE_DIALOG, - "HildonFontSelectionDialog", - &fontsel_diag_info, 0); - } - - return font_selection_dialog_type; -} - -static void -hildon_font_selection_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - gint i; - GdkColor color; - - HildonFontSelectionDialogPrivate *priv = - HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(object); - - g_assert (priv); - - switch (prop_id) - { - case PROP_FAMILY: - i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_type)); - if(i >= 0 && i < priv->n_families) - g_value_set_string(value, - pango_font_family_get_name (priv->families[i])); - else - g_value_set_string (value, "Sans"); - /* FIXME Bad hardcoding here */ - break; - - case PROP_FAMILY_SET: - i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_type)); - if(i >= 0 && i < priv->n_families) - g_value_set_boolean (value, TRUE); - else - g_value_set_boolean (value, FALSE); - break; - - case PROP_SIZE: - i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_size)); - if(i >= 0 && i < G_N_ELEMENTS (font_sizes)) - g_value_set_int (value, font_sizes[i]); - else - g_value_set_int (value, 16); - break; - - case PROP_SIZE_SET: - i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_size)); - if(i >= 0 && i < G_N_ELEMENTS (font_sizes)) - g_value_set_boolean (value, TRUE); - else - g_value_set_boolean (value, FALSE); - break; - - case PROP_COLOR: - hildon_color_button_get_color - (HILDON_COLOR_BUTTON (priv->font_color_button), &color); - g_value_set_boxed (value, (gconstpointer) &color); - break; - - case PROP_COLOR_SET: - g_value_set_boolean (value, priv->color_set); - break; - - case PROP_BOLD: - g_value_set_boolean (value, - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->chk_bold))); - break; - - case PROP_BOLD_SET: - g_value_set_boolean (value, - ! gtk_toggle_button_get_inconsistent - (GTK_TOGGLE_BUTTON (priv->chk_bold))); - break; - - case PROP_ITALIC: - g_value_set_boolean (value, - gtk_toggle_button_get_active - (GTK_TOGGLE_BUTTON (priv->chk_italic))); - break; - - case PROP_ITALIC_SET: - g_value_set_boolean (value, - ! gtk_toggle_button_get_inconsistent - (GTK_TOGGLE_BUTTON (priv->chk_italic))); - break; - - case PROP_UNDERLINE: - g_value_set_boolean (value, - gtk_toggle_button_get_active - (GTK_TOGGLE_BUTTON (priv->chk_underline))); - break; - - case PROP_UNDERLINE_SET: - g_value_set_boolean (value, - ! gtk_toggle_button_get_inconsistent - (GTK_TOGGLE_BUTTON (priv->chk_underline))); - break; - - case PROP_STRIKETHROUGH: - g_value_set_boolean(value, - gtk_toggle_button_get_active - (GTK_TOGGLE_BUTTON (priv->chk_strikethrough))); - break; - - case PROP_STRIKETHROUGH_SET: - g_value_set_boolean(value, - ! gtk_toggle_button_get_inconsistent - (GTK_TOGGLE_BUTTON (priv->chk_strikethrough))); - break; - - case PROP_POSITION: - i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_positioning)); - if(i == 1) /* super */ - g_value_set_int (value, 1); - else if(i == 2)/* sub */ - g_value_set_int (value, -1); - else - g_value_set_int (value, 0); - break; - - case PROP_FONT_SCALING: - g_value_set_double (value, priv->font_scaling); - break; - - case PROP_POSITION_SET: - i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_positioning)); - if(i >= 0 && i < 3) - g_value_set_boolean (value, TRUE); - else - g_value_set_boolean (value, FALSE); - break; - - case PROP_PREVIEW_TEXT: - g_value_set_string (value, - hildon_font_selection_dialog_get_preview_text (HILDON_FONT_SELECTION_DIALOG (object))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_font_selection_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - gint i, size; - const gchar *family; - gboolean b; - GdkColor *color = NULL; - GdkColor black; - - HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (object); - g_assert (priv); - - black.red = black.green = black.blue = 0; - - switch (prop_id) - { - case PROP_FAMILY: - family = g_value_get_string (value); - g_return_if_fail (family != NULL); - for(i = 0; i < priv->n_families; i++) - { - if (strcmp (family, pango_font_family_get_name (priv->families[i])) - == 0) - { - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_type), i); - break; - } - } - break; - - case PROP_FAMILY_SET: - b = g_value_get_boolean (value); - if(!b) - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_type), -1); - break; - - case PROP_SIZE: - size = g_value_get_int (value); - for(i = 0; i < G_N_ELEMENTS (font_sizes); i++) - { - if(size == font_sizes[i]) - { - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_size), i); - break; - } - } - break; - - case PROP_SIZE_SET: - b = g_value_get_boolean (value); - if(!b) - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_size), -1); - break; - - case PROP_COLOR: - color = (GdkColor *) g_value_get_boxed (value); - if(color != NULL) - hildon_color_button_set_color (HILDON_COLOR_BUTTON - (priv->font_color_button), - color); - else - hildon_color_button_set_color (HILDON_COLOR_BUTTON - (priv->font_color_button), - &black); - break; - - case PROP_COLOR_SET: - priv->color_set = g_value_get_boolean (value); - if(! priv->color_set) - { - /* set color to black, but block our signal handler */ - g_signal_handler_block ((gpointer) priv->font_color_button, - priv->color_modified_signal_handler); - - hildon_color_button_set_color (HILDON_COLOR_BUTTON - (priv->font_color_button), - &black); - - g_signal_handler_unblock ((gpointer) priv->font_color_button, - priv->color_modified_signal_handler); - } - break; - - case PROP_BOLD: - /* this call will make sure that we dont get extra clicked signal */ - gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON(priv->chk_bold), FALSE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(priv->chk_bold), g_value_get_boolean (value)); - break; - - case PROP_BOLD_SET: - gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (priv->chk_bold),! g_value_get_boolean(value)); - break; - - case PROP_ITALIC: - gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_italic), - FALSE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_italic), - g_value_get_boolean(value)); - break; - - case PROP_ITALIC_SET: - gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_italic), - !g_value_get_boolean(value)); - break; - - case PROP_UNDERLINE: - gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON - (priv->chk_underline), - FALSE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_underline), - g_value_get_boolean(value)); - break; - - case PROP_UNDERLINE_SET: - gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_underline), - !g_value_get_boolean(value)); - break; - - case PROP_STRIKETHROUGH: - gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON - (priv->chk_strikethrough), - FALSE); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_strikethrough), - g_value_get_boolean(value)); - break; - - case PROP_STRIKETHROUGH_SET: - gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON - (priv->chk_strikethrough), - !g_value_get_boolean(value)); - break; - - case PROP_POSITION: - i = g_value_get_int(value); - if( i == 1 ) - gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 1); - else if(i == -1) - gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 2); - else - gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 0); - break; - - case PROP_FONT_SCALING: - priv->font_scaling = g_value_get_double(value); - break; - - case PROP_POSITION_SET: - b = g_value_get_boolean(value); - if(!b) - gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), -1); - break; - - case PROP_PREVIEW_TEXT: - hildon_font_selection_dialog_set_preview_text( - HILDON_FONT_SELECTION_DIALOG(object), - g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_font_selection_dialog_class_init (HildonFontSelectionDialogClass *klass) -{ - GObjectClass *gobject_class; - - parent_class = g_type_class_peek_parent (klass); - gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = hildon_font_selection_dialog_finalize; - gobject_class->get_property = hildon_font_selection_dialog_get_property; - gobject_class->set_property = hildon_font_selection_dialog_set_property; - - /* Install properties to the class */ - - /** - * HildonFontSelectionDialog:family: - * - * Font family used. - */ - g_object_class_install_property (gobject_class, PROP_FAMILY, - g_param_spec_string ("family", - "Font family", "String defines" - " the font family", "Sans", - G_PARAM_READWRITE)); - - /** - * HildonFontSelectionDialog:family-set: - * - * Is font family set or inconsistent. - */ - g_object_class_install_property (gobject_class, PROP_FAMILY_SET, - g_param_spec_boolean ("family-set", - "family inconsistent state", - "Whether the family property" - " is inconsistent", FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /** - * HildonFontSelectionDialog:size: - * - * Font size. - */ - g_object_class_install_property (gobject_class, PROP_SIZE, - g_param_spec_int ("size", - "Font size", - "Font size in Pt", - 6, 32, 16, - G_PARAM_READWRITE)); - - /** - * HildonFontSelectionDialog:size-set: - * - * Is font size set or inconsistent. - */ - g_object_class_install_property (gobject_class, PROP_SIZE_SET, - g_param_spec_boolean ("size-set", - "size inconsistent state", - "Whether the size property" - " is inconsistent", FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /** - * HildonFontSelectionDialog:color: - * - * GdkColor for the text. - */ - g_object_class_install_property (gobject_class, PROP_COLOR, - g_param_spec_boxed ("color", - "text color", - "gdk color for the text", - GDK_TYPE_COLOR, - G_PARAM_READWRITE)); - - /** - * HildonFontSelectionDialog:color-set: - * - * Is font color set or inconsistent. - */ - g_object_class_install_property (gobject_class, PROP_COLOR_SET, - g_param_spec_boolean ("color-set", - "color inconsistent state", - "Whether the color property" - " is inconsistent", FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /** - * HildonFontSelectionDialog:color-set: - * - * Is font set as bold. - */ - g_object_class_install_property (gobject_class, PROP_BOLD, - g_param_spec_boolean ("bold", - "text weight", - "Whether the text is bold", - FALSE, - G_PARAM_READWRITE)); - - /** - * HildonFontSelectionDialog:color-set: - * - * Is font bold status set or inconsistent. - */ - g_object_class_install_property (gobject_class, PROP_BOLD_SET, - g_param_spec_boolean ("bold-set", - "bold inconsistent state", - "Whether the bold" - " is inconsistent", FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /** - * HildonFontSelectionDialog:italic: - * - * Is font set as italic. - */ - g_object_class_install_property (gobject_class, PROP_ITALIC, - g_param_spec_boolean ("italic", - "text style", - "Whether the text is italic", - FALSE, - G_PARAM_READWRITE)); - - /** - * HildonFontSelectionDialog:italic-set: - * - * Is font italic status set or inconsistent. - */ - g_object_class_install_property (gobject_class, PROP_ITALIC_SET, - g_param_spec_boolean ("italic-set", - "italic inconsistent state", - "Whether the italic" - " is inconsistent", FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /** - * HildonFontSelectionDialog:underline: - * - * Is the font underlined. - */ - g_object_class_install_property (gobject_class, PROP_UNDERLINE, - g_param_spec_boolean ("underline", - "text underline", - "Whether the text is underlined", - FALSE, - G_PARAM_READWRITE)); - - /** - * HildonFontSelectionDialog:underline: - * - * Is font underline status set or inconsistent. - */ - g_object_class_install_property (gobject_class, PROP_UNDERLINE_SET, - g_param_spec_boolean ("underline-set", - "underline inconsistent state", - "Whether the underline" - " is inconsistent", FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /** - * HildonFontSelectionDialog:strikethrough: - * - * Is the font striken-through. - */ - g_object_class_install_property (gobject_class, PROP_STRIKETHROUGH, - g_param_spec_boolean ("strikethrough", - "strikethroughed text", - "Whether the text is strikethroughed", - FALSE, - G_PARAM_READWRITE)); - - /** - * HildonFontSelectionDialog:strikethrough-set: - * - * Is the font strikenthrough status set. - */ - g_object_class_install_property (gobject_class, PROP_STRIKETHROUGH_SET, - g_param_spec_boolean ("strikethrough-set", - "strikethrough inconsistent state", - "Whether the strikethrough" - " is inconsistent", FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /** - * HildonFontSelectionDialog:position: - * - * The font positioning versus baseline. - */ - g_object_class_install_property (gobject_class, PROP_POSITION, - g_param_spec_int ("position", - "Font position", - "Font position super or subscript", - -1, 1, 0, - G_PARAM_READWRITE)); - - /** - * HildonFontSelectionDialog:position-set: - * - * Is the font positioning set. - */ - g_object_class_install_property (gobject_class, PROP_POSITION_SET, - g_param_spec_boolean ("position-set", - "position inconsistent state", - "Whether the position" - " is inconsistent", FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - /** - * HildonFontSelectionDialog:font-scaling: - * - * The font scaling factor applied to the preview dialog. - */ - g_object_class_install_property (gobject_class, PROP_FONT_SCALING, - g_param_spec_double ("font-scaling", - "Font scaling", - "Font scaling for the preview dialog", - 0, 10, 1, - G_PARAM_READWRITE)); - - /** - * HildonFontSelectionDialog:preview-text: - * - * The text used for the preview dialog. - * - * Deprecated: this property is unused since hildon 2.2 - */ - g_object_class_install_property (gobject_class, PROP_PREVIEW_TEXT, - g_param_spec_string("preview-text", - "Preview Text", - "the text in preview dialog, which does" - "not include the reference text", - "", - G_PARAM_READWRITE)); - - g_type_class_add_private (klass, - sizeof (struct _HildonFontSelectionDialogPrivate)); -} - -static void -hildon_font_selection_dialog_init (HildonFontSelectionDialog *fontseldiag) -{ - HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontseldiag); - /* GtkWidget *preview_button; */ - - g_assert (priv); - priv->notebook = GTK_NOTEBOOK (gtk_notebook_new ()); - - hildon_font_selection_dialog_construct_notebook (fontseldiag); - - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (fontseldiag)->vbox), - GTK_WIDGET (priv->notebook), TRUE, TRUE, 0); - - /* Add dialog buttons */ - gtk_dialog_add_button (GTK_DIALOG (fontseldiag), - HILDON_STOCK_DONE, GTK_RESPONSE_OK); - -#if 0 - preview_button = gtk_button_new_with_label (_("ecdg_bd_font_dialog_preview")); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG (fontseldiag)->action_area), - preview_button, FALSE, TRUE, 0); - - g_signal_connect_swapped (preview_button, "clicked", - G_CALLBACK - (hildon_font_selection_dialog_show_preview), - fontseldiag); - gtk_widget_show(preview_button); -#endif - - /*Set default preview text*/ - priv->preview_text = g_strdup (_("ecdg_fi_preview_font_preview_text")); - - gtk_window_set_title (GTK_WINDOW (fontseldiag), _("ecdg_ti_font")); - /*here is the line to make sure that notebook has the default focus*/ - gtk_container_set_focus_child (GTK_CONTAINER (GTK_DIALOG (fontseldiag)->vbox), - GTK_WIDGET (priv->notebook)); -} - -static void -hildon_font_selection_dialog_construct_notebook (HildonFontSelectionDialog *fontsel) -{ - gint i; - GtkWidget *vbox_tab[3]; - GtkWidget *font_color_box; - GtkWidget *caption_control; - GtkSizeGroup *group; - - HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel); - g_assert (priv); - - for (i = 0; i < 3; i++) - vbox_tab[i] = gtk_vbox_new (TRUE, 0); - - group = GTK_SIZE_GROUP (gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL)); - - /* Build the first page of the GtkNotebook: font style */ - priv->cbx_font_type = gtk_combo_box_new_text (); - hildon_font_selection_dialog_show_available_fonts (fontsel); - caption_control = hildon_caption_new (group, - _("ecdg_fi_font_font"), - priv->cbx_font_type, - NULL, - HILDON_CAPTION_OPTIONAL); - - gtk_box_pack_start (GTK_BOX (vbox_tab[0]), caption_control, FALSE, FALSE, 0); - - priv->cbx_font_size = gtk_combo_box_new_text (); - hildon_font_selection_dialog_show_available_sizes (priv); - caption_control = hildon_caption_new (group, - _("ecdg_fi_font_size"), - priv->cbx_font_size, - NULL, - HILDON_CAPTION_OPTIONAL); - - gtk_box_pack_start (GTK_BOX (vbox_tab[0]), caption_control, FALSE, FALSE, 0); - - font_color_box = gtk_hbox_new (FALSE, 0); - priv->font_color_button = hildon_color_button_new (); - priv->color_set = FALSE; - priv->font_scaling = 1.0; - priv->color_modified_signal_handler = - g_signal_connect (G_OBJECT (priv->font_color_button), "notify::color", - G_CALLBACK (color_modified_cb), (gpointer) priv); - - gtk_box_pack_start (GTK_BOX (font_color_box), priv->font_color_button, FALSE, FALSE, 0); - - caption_control = - hildon_caption_new (group, _("ecdg_fi_font_colour_selector"), - font_color_box, - NULL, HILDON_CAPTION_OPTIONAL); - - gtk_box_pack_start (GTK_BOX (vbox_tab[0]), caption_control, FALSE, FALSE, 0); - - /* Build the second page of the GtkNotebook: font formatting */ - priv->chk_bold = gtk_check_button_new (); - caption_control = hildon_caption_new (group, - _("ecdg_fi_font_bold"), - priv->chk_bold, - NULL, - HILDON_CAPTION_OPTIONAL); - - gtk_box_pack_start (GTK_BOX (vbox_tab[1]), caption_control, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT (priv->chk_bold), "clicked", - G_CALLBACK(toggle_clicked), NULL); - - priv->chk_italic = gtk_check_button_new (); - caption_control = hildon_caption_new (group, _("ecdg_fi_font_italic"), - priv->chk_italic, - NULL, HILDON_CAPTION_OPTIONAL); - - gtk_box_pack_start (GTK_BOX (vbox_tab[1]), caption_control, FALSE, FALSE, 0); - g_signal_connect(G_OBJECT(priv->chk_italic), "clicked", - G_CALLBACK(toggle_clicked), NULL); - - priv->chk_underline = gtk_check_button_new(); - caption_control = - hildon_caption_new (group, _("ecdg_fi_font_underline"), - priv->chk_underline, NULL, - HILDON_CAPTION_OPTIONAL); - - gtk_box_pack_start (GTK_BOX (vbox_tab[1]), caption_control, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT(priv->chk_underline), "clicked", - G_CALLBACK (toggle_clicked), NULL); - - /* Build the third page of the GtkNotebook: other font properties */ - priv->chk_strikethrough = gtk_check_button_new (); - caption_control = hildon_caption_new(group, _("ecdg_fi_font_strikethrough"), - priv->chk_strikethrough, NULL, - HILDON_CAPTION_OPTIONAL); - - gtk_box_pack_start (GTK_BOX (vbox_tab[2]), caption_control, FALSE, FALSE, 0); - g_signal_connect (G_OBJECT(priv->chk_strikethrough), "clicked", - G_CALLBACK (toggle_clicked), NULL); - - priv->cbx_positioning = gtk_combo_box_new_text (); - hildon_font_selection_dialog_show_available_positionings (priv); - caption_control = - hildon_caption_new(group, _("ecdg_fi_font_special"), - priv->cbx_positioning, NULL, - HILDON_CAPTION_OPTIONAL); - - g_object_unref (group); - - gtk_box_pack_start (GTK_BOX (vbox_tab[2]), caption_control, FALSE, FALSE, 0); - - /* Populate notebook */ - gtk_notebook_insert_page (priv->notebook, vbox_tab[0], NULL, 0); - gtk_notebook_insert_page (priv->notebook, vbox_tab[1], NULL, 1); - gtk_notebook_insert_page (priv->notebook, vbox_tab[2], NULL, 2); - - gtk_notebook_set_tab_label_text (priv->notebook, vbox_tab[0], - _("ecdg_ti_font_dialog_style")); - gtk_notebook_set_tab_label_text (priv->notebook, vbox_tab[1], - _("ecdg_ti_font_dialog_format")); - gtk_notebook_set_tab_label_text (priv->notebook, vbox_tab[2], - _("ecdg_ti_font_dialog_other")); - - gtk_widget_show_all (GTK_WIDGET (priv->notebook)); -} - -static void -color_modified_cb (HildonColorButton *button, - GParamSpec *pspec, - gpointer fsd_priv) -{ - HildonFontSelectionDialogPrivate *priv = (HildonFontSelectionDialogPrivate *) fsd_priv; - g_assert (priv); - - priv->color_set = TRUE; -} - -static void -hildon_font_selection_dialog_finalize (GObject *object) -{ - HildonFontSelectionDialogPrivate *priv; - HildonFontSelectionDialog *fontsel; - - g_assert (HILDON_IS_FONT_SELECTION_DIALOG (object)); - fontsel = HILDON_FONT_SELECTION_DIALOG (object); - - priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel); - g_assert (priv); - - if (priv->preview_text != NULL) { - g_free (priv->preview_text); - priv->preview_text = NULL; - } - - if (priv->families != NULL) { - g_free (priv->families); - priv->families = NULL; - } - - if (G_OBJECT_CLASS (parent_class)->finalize) - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static int -cmp_families (const void *a, - const void *b) -{ - const char *a_name = - pango_font_family_get_name (* (PangoFontFamily **) a); - - const char *b_name = - pango_font_family_get_name (* (PangoFontFamily **) b); - - return g_utf8_collate (a_name, b_name); -} - -#if 0 -/* Exits the preview dialog with GTK_RESPONSE_CANCEL if Esc key - * was pressed - * FIXME This should be handled automatically */ -static gboolean -hildon_font_selection_dialog_preview_key_press (GtkWidget *widget, - GdkEventKey *event, - gpointer unused) -{ - g_assert (widget); - g_assert (event); - - if (event->keyval == GDK_Escape) - { - gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_CANCEL); - return TRUE; - } - - return FALSE; -} - -static void -add_preview_text_attr (PangoAttrList *list, - PangoAttribute *attr, - guint start, - guint len) -{ - attr->start_index = start; - attr->end_index = start + len; - pango_attr_list_insert (list, attr); -} - -static PangoAttrList* -hildon_font_selection_dialog_create_attrlist (HildonFontSelectionDialog *fontsel, - guint start_index, - guint len) -{ - PangoAttrList *list; - PangoAttribute *attr; - gint size, position; - gboolean family_set, size_set, color_set, bold, bold_set, - italic, italic_set, underline, underline_set, - strikethrough, strikethrough_set, position_set; - GdkColor *color = NULL; - gchar *family = NULL; - gdouble font_scaling = 1.0; - - list = pango_attr_list_new (); - - g_object_get (G_OBJECT (fontsel), - "family", &family, "family-set", &family_set, - "size", &size, "size-set", &size_set, - "color", &color, "color-set", &color_set, - "bold", &bold, "bold-set", &bold_set, - "italic", &italic, "italic-set", &italic_set, - "underline", &underline, "underline-set", &underline_set, - "strikethrough", &strikethrough, "strikethrough-set", - &strikethrough_set, "position", &position, - "position-set", &position_set, - "font-scaling", &font_scaling, - NULL); - - /* family */ - if (family_set) - { - attr = pango_attr_family_new (family); - add_preview_text_attr (list, attr, start_index, len); - } - g_free (family); - - /* size */ - if (size_set) - { - attr = pango_attr_size_new (size * PANGO_SCALE); - add_preview_text_attr (list, attr, start_index, len); - } - - /*color*/ - if (color_set) - { - attr = pango_attr_foreground_new (color->red, color->green, color->blue); - add_preview_text_attr (list, attr, start_index, len); - } - - if (color != NULL) - gdk_color_free (color); - - /*weight*/ - if (bold_set) - { - if (bold) - attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD); - else - attr = pango_attr_weight_new (PANGO_WEIGHT_NORMAL); - - add_preview_text_attr(list, attr, start_index, len); - } - - /* style */ - if (italic_set) - { - if (italic) - attr = pango_attr_style_new (PANGO_STYLE_ITALIC); - else - attr = pango_attr_style_new (PANGO_STYLE_NORMAL); - - add_preview_text_attr(list, attr, start_index, len); - } - - /* underline */ - if (underline_set) - { - if (underline) - attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); - else - attr = pango_attr_underline_new (PANGO_UNDERLINE_NONE); - - add_preview_text_attr(list, attr, start_index, len); - } - - /* strikethrough */ - if (strikethrough_set) - { - if (strikethrough) - attr = pango_attr_strikethrough_new (TRUE); - else - attr = pango_attr_strikethrough_new (FALSE); - - add_preview_text_attr(list, attr, start_index, len); - } - - /* position */ - if (position_set) - { - switch (position) - { - case 1: /*super*/ - attr = pango_attr_rise_new (SUPERSCRIPT_RISE); - break; - case -1: /*sub*/ - attr = pango_attr_rise_new (SUBSCRIPT_LOW); - break; - default: /*normal*/ - attr = pango_attr_rise_new (0); - break; - } - - add_preview_text_attr (list, attr, start_index, len); - } - - /* font scaling for preview */ - if (font_scaling) - { - attr = pango_attr_scale_new(font_scaling); - add_preview_text_attr(list, attr, 0, len + start_index); - } - - return list; -} - -static void -hildon_font_selection_dialog_show_preview (HildonFontSelectionDialog *fontsel) -{ - HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel); - gint size; - gboolean family_set, size_set; - PangoAttribute *attr; - PangoAttrList *list; - GtkWidget *preview_dialog; - GtkWidget *preview_label; - gchar *str = NULL; - gboolean position_set = FALSE; - gint position = 0; - gboolean show_ref = FALSE; - - g_assert (priv); - - g_object_get (G_OBJECT (fontsel), "position-set", &position_set, NULL); - - if (position_set) { - g_object_get (G_OBJECT (fontsel), "position", &position, NULL); - if (position == 1 || position == -1) - show_ref = TRUE; - } - - /* preview dialog init */ - preview_dialog = - gtk_dialog_new_with_buttons (_("ecdg_ti_preview_font"), NULL, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, - HILDON_STOCK_DONE, GTK_RESPONSE_ACCEPT, - NULL); - - str = (show_ref) ? g_strconcat (_("ecdg_fi_preview_font_preview_reference"), priv->preview_text, 0) : - g_strdup (priv->preview_text); - - preview_label = gtk_label_new (str); - gtk_label_set_line_wrap (GTK_LABEL(preview_label), TRUE); - - if (str) - g_free (str); - - str = NULL; - - /* set keypress handler (ESC hardkey) */ - g_signal_connect (G_OBJECT (preview_dialog), "key-press-event", - G_CALLBACK(hildon_font_selection_dialog_preview_key_press), - NULL); - - /* Set the font */ - list = (show_ref) ? hildon_font_selection_dialog_create_attrlist (fontsel, - strlen (_("ecdg_fi_preview_font_preview_reference")), - strlen (priv->preview_text)) : - hildon_font_selection_dialog_create_attrlist (fontsel, 0, strlen(priv->preview_text)); - - g_object_get (G_OBJECT (fontsel), "family", &str, "family-set", - &family_set, "size", &size, "size-set", &size_set, - NULL); - - /* A smallish hack to add scrollbar when font size is really big */ - - if (size_set && size > 24) { - GtkScrolledWindow *scrolled = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL)); - gtk_scrolled_window_set_policy (scrolled, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_add_with_viewport (scrolled, GTK_WIDGET (preview_label)); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG(preview_dialog)->vbox), GTK_WIDGET (scrolled)); - gtk_widget_set_size_request (GTK_WIDGET (scrolled), -1, 400); - } else - gtk_container_add (GTK_CONTAINER (GTK_DIALOG(preview_dialog)->vbox), GTK_WIDGET (preview_label)); - - /* make reference text to have the same fontface and size */ - if (family_set) - { - attr = pango_attr_family_new (str); - add_preview_text_attr (list, attr, 0, strlen (_("ecdg_fi_preview_font_preview_reference"))); - } - if (str != NULL) - g_free (str); - - str = NULL; - - /* size */ - if (size_set) - { - attr = pango_attr_size_new (size * PANGO_SCALE); - add_preview_text_attr (list, attr, 0, strlen (_("ecdg_fi_preview_font_preview_reference"))); - } - - gtk_label_set_attributes (GTK_LABEL (preview_label), list); - pango_attr_list_unref (list); - - /*And show the dialog*/ - gtk_window_set_transient_for (GTK_WINDOW (preview_dialog), - GTK_WINDOW (fontsel)); - - gtk_widget_show_all (preview_dialog); - gtk_dialog_set_default_response (GTK_DIALOG (preview_dialog), GTK_RESPONSE_OK); - - GtkBox *action_area = (GtkBox *) GTK_DIALOG (preview_dialog)->action_area; - GtkWidget *button = ((GtkBoxChild *) ((GSList *) action_area->children)->data)->widget; - gtk_widget_grab_focus (button); - - gtk_dialog_run (GTK_DIALOG (preview_dialog)); - gtk_widget_destroy (preview_dialog); -} -#endif - -static gboolean -is_internal_font (const gchar * name) -{ - /* FIXME Extremally BAD BAD BAD way of doing things */ - - return strcmp(name, "DeviceSymbols") == 0 - || strcmp(name, "Nokia Smiley" ) == 0 - || strcmp(name, "NewCourier" ) == 0 - || strcmp(name, "NewTimes" ) == 0 - || strcmp(name, "SwissA" ) == 0 - || strcmp(name, "Nokia Sans" ) == 0 - || strcmp(name, "Nokia Sans Cn") == 0; -} - -static void -filter_out_internal_fonts (PangoFontFamily **families, - int *n_families) -{ - int i; - int n; /* counts valid fonts */ - const gchar * name = NULL; - - for(i = 0, n = 0; i < * n_families; i++){ - - name = pango_font_family_get_name (families[i]); - - if(!is_internal_font(name)) - { - - if (i!=n){ /* there are filtered out families */ - families[n] = families[i]; /* shift the current family */ - } - - n++; /* count one more valid */ - } - } /* foreach font family */ - - *n_families = n; -} - -static void -hildon_font_selection_dialog_show_available_fonts (HildonFontSelectionDialog *fontsel) - -{ - gint i; - - HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel); - g_assert (priv); - - pango_context_list_families (gtk_widget_get_pango_context - (GTK_WIDGET (fontsel)), &priv->families, - &priv->n_families); - - filter_out_internal_fonts (priv->families, &priv->n_families); - - qsort (priv->families, priv->n_families, sizeof(PangoFontFamily *), cmp_families); - - for (i = 0; i < priv->n_families; i++) - { - const gchar *name = pango_font_family_get_name (priv->families[i]); - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_font_type), name); - } -} - -static void -hildon_font_selection_dialog_show_available_positionings (HildonFontSelectionDialogPrivate *priv) -{ - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_positioning), _("ecdg_va_font_printpos_1")); - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_positioning), _("ecdg_va_font_printpos_2")); - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_positioning), _("ecdg_va_font_printpos_3")); -} - -/* Loads the sizes from a pre-allocated table */ -static void -hildon_font_selection_dialog_show_available_sizes (HildonFontSelectionDialogPrivate *priv) -{ - gchar *size_str; - gint i; - - g_assert (priv); - - for (i = 0; i < G_N_ELEMENTS (font_sizes); i++) - { - size_str = g_strdup_printf ("%i%s", - font_sizes[i], - _("ecdg_va_font_size_trailer")); - - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_font_size), size_str); - g_free (size_str); - } -} - -static void -toggle_clicked (GtkButton *button, - gpointer unused) -{ - GtkToggleButton *t_b = GTK_TOGGLE_BUTTON (button); - - /* we have to remove the inconsistent state ourselves */ - if (gtk_toggle_button_get_inconsistent (t_b)) - { - gtk_toggle_button_set_inconsistent (t_b, FALSE); - gtk_toggle_button_set_active (t_b, FALSE); - } -} - -/** - * hildon_font_selection_dialog_new: - * @parent: the parent window - * @title: the title of font selection dialog - * - * If NULL is passed for title, then default title - * "Font" will be used. - * - * Returns: a new #HildonFontSelectionDialog - */ -GtkWidget* -hildon_font_selection_dialog_new (GtkWindow *parent, - const gchar *title) -{ - HildonFontSelectionDialog *fontseldiag; - - fontseldiag = g_object_new (HILDON_TYPE_FONT_SELECTION_DIALOG, - "has-separator", FALSE, NULL); - - if (title) - gtk_window_set_title (GTK_WINDOW (fontseldiag), title); - - if (parent) - gtk_window_set_transient_for (GTK_WINDOW (fontseldiag), parent); - - return GTK_WIDGET (fontseldiag); -} - -/** - * hildon_font_selection_dialog_get_preview_text: - * @fsd: the font selection dialog - * - * Gets the text in preview dialog, which does not include the - * reference text. The returned string must be freed by the user. - * Please note that since hildon 2.2, the preview has been discontinued, - * so this setting has no effect. - * - * Returns: a string pointer - */ -gchar* -hildon_font_selection_dialog_get_preview_text (HildonFontSelectionDialog * fsd) -{ - /* FIXME Return a const pointer? */ - HildonFontSelectionDialogPrivate *priv; - - g_return_val_if_fail (HILDON_IS_FONT_SELECTION_DIALOG (fsd), NULL); - - priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fsd); - g_assert (priv); - - return g_strdup (priv->preview_text); -} - -/** - * hildon_font_selection_dialog_set_preview_text: - * @fsd: the font selection dialog - * @text: the text to be displayed in the preview dialog - * - * The default preview text is - * "The quick brown fox jumped over the lazy dogs". Please note that since - * hildon 2.2, the preview has been discontinued, so this setting has no effect. - * - */ -void -hildon_font_selection_dialog_set_preview_text (HildonFontSelectionDialog *fsd, - const gchar * text) -{ - HildonFontSelectionDialogPrivate *priv = NULL; - - g_return_if_fail (HILDON_IS_FONT_SELECTION_DIALOG (fsd)); - g_return_if_fail (text); - - priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fsd); - g_assert (priv); - - g_free (priv->preview_text); - priv->preview_text = g_strdup (text); - g_object_notify (G_OBJECT (fsd), "preview-text"); -} - diff --git a/hildon/hildon-font-selection-dialog.h b/hildon/hildon-font-selection-dialog.h deleted file mode 100644 index 558f660..0000000 --- a/hildon/hildon-font-selection-dialog.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_FONT_SELECTION_DIALOG_H__ -#define __HILDON_FONT_SELECTION_DIALOG_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_FONT_SELECTION_DIALOG \ - (hildon_font_selection_dialog_get_type ()) - -#define HILDON_FONT_SELECTION_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj),\ - HILDON_TYPE_FONT_SELECTION_DIALOG, HildonFontSelectionDialog)) - -#define HILDON_FONT_SELECTION_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_FONT_SELECTION_DIALOG,\ - HildonFontSelectionDialogClass)) - -#define HILDON_IS_FONT_SELECTION_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ - HILDON_TYPE_FONT_SELECTION_DIALOG)) - -#define HILDON_IS_FONT_SELECTION_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass),\ - HILDON_TYPE_FONT_SELECTION_DIALOG)) - -#define HILDON_FONT_SELECTION_DIALOG_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj),\ - HILDON_TYPE_FONT_SELECTION_DIALOG,\ - HildonFontSelectionDialogClass)) - -typedef struct _HildonFontSelectionDialog HildonFontSelectionDialog; - -typedef struct _HildonFontSelectionDialogClass HildonFontSelectionDialogClass; - -struct _HildonFontSelectionDialog -{ - GtkDialog parent; -}; - -struct _HildonFontSelectionDialogClass -{ - GtkDialogClass parent_class; -}; - -GType G_GNUC_CONST -hildon_font_selection_dialog_get_type (void); - -GtkWidget* -hildon_font_selection_dialog_new (GtkWindow *parent, - const gchar *title); - -gchar* -hildon_font_selection_dialog_get_preview_text (HildonFontSelectionDialog *fsd); - -void -hildon_font_selection_dialog_set_preview_text (HildonFontSelectionDialog *fsd, - const gchar * text); - -G_END_DECLS - -#endif /* __HILDON_FONT_SELECTION_DIALOG_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-get-password-dialog-private.h b/hildon/hildon-get-password-dialog-private.h deleted file mode 100644 index a6bdf6e..0000000 --- a/hildon/hildon-get-password-dialog-private.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_GET_PASSWORD_DIALOG_PRIVATE_H__ -#define __HILDON_GET_PASSWORD_DIALOG_PRIVATE_H__ - -G_BEGIN_DECLS - -#define HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_GET_PASSWORD_DIALOG, HildonGetPasswordDialogPrivate)); - -typedef struct _HildonGetPasswordDialogPrivate HildonGetPasswordDialogPrivate; - -struct _HildonGetPasswordDialogPrivate -{ - GtkLabel *message_label; - HildonCaption *password_entry; - gboolean get_old; -}; - -G_END_DECLS - -#endif /* __HILDON_GET_PASSWORD_DIALOG_PRIVATE_H__ */ diff --git a/hildon/hildon-get-password-dialog.c b/hildon/hildon-get-password-dialog.c deleted file mode 100644 index a1eabcd..0000000 --- a/hildon/hildon-get-password-dialog.c +++ /dev/null @@ -1,673 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006, 2009 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-get-password-dialog - * @short_description: A widget used to get a password. - * @see_also: #HildonSetPasswordDialog - * - * HildonGetPasswordDialog prompts the user for a password. It allows - * inputting password, with an optional configurable label eg. for - * showing a custom message. The maximum length of the password can be set. - * - * <example> - * <title>HildonGetPassword example</title> - * <programlisting> - * get_dialog = HILDON_GET_PASSWORD_DIALOG (hildon_get_password_dialog_new (parent, FALSE)); - * <!-- --> - * gtk_widget_show (GTK_WIDGET (get_dialog)); - * <!-- --> - * i = gtk_dialog_run (GTK_DIALOG (get_dialog)); - * <!-- --> - * pass = hildon_get_password_dialog_get_password (get_dialog); - * <!-- --> - * if (i == GTK_RESPONSE_OK && (strcmp (pass, dialog.current_password) != 0)) - * { - * gtk_infoprint (GTK_WINDOW (parent), STR_PASSWORD_INCORRECT); - * gtk_widget_set_sensitive (GTK_WIDGET (dialog.button2), FALSE); - * gtk_widget_set_sensitive (GTK_WIDGET (dialog.button3), FALSE); - * gtk_widget_set_sensitive (GTK_WIDGET (dialog.button4), FALSE); - * } - * <!-- --> - * else if (i == GTK_RESPONSE_OK) - * { - * gtk_widget_set_sensitive( GTK_WIDGET( dialog.button2 ), TRUE); - * } - * <!-- --> - * else - * { - * gtk_widget_set_sensitive (GTK_WIDGET (dialog.button2), FALSE); - * gtk_widget_set_sensitive (GTK_WIDGET (dialog.button3), FALSE); - * gtk_widget_set_sensitive (GTK_WIDGET (dialog.button4), FALSE); - * } - * gtk_widget_destroy (GTK_WIDGET (get_dialog)); - * } - * </programlisting> - * </example> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <errno.h> -#include <string.h> -#include <strings.h> -#include <unistd.h> -#include <stdio.h> -#include <libintl.h> - -#include "hildon-get-password-dialog.h" -#include "hildon-caption.h" -#include "hildon-banner.h" -#include "hildon-get-password-dialog-private.h" -#include "hildon-entry.h" -#include "hildon-stock.h" - -#define _(String) dgettext("hildon-libs", String) - -#define HILDON_GET_PASSWORD_DIALOG_TITLE "ecdg_ti_get_old_password" - -#define HILDON_GET_PASSWORD_DIALOG_PASSWORD "ecdg_fi_get_old_pwd_enter_pwd" - -#define HILDON_GET_PASSWORD_DIALOG_OK HILDON_STOCK_DONE - -#define HILDON_GET_PASSWORD_DIALOG_CANCEL "ecdg_bd_get_old_password_dialog_cancel" - -#define HILDON_GET_PASSWORD_VERIFY_DIALOG_TITLE "ecdg_ti_verify_password" - -#define HILDON_GET_PASSWORD_VERIFY_DIALOG_PASSWORD "ecdg_fi_verify_pwd_enter_pwd" - -#define HILDON_GET_PASSWORD_VERIFY_DIALOG_OK HILDON_STOCK_DONE - -#define HILDON_GET_PASSWORD_VERIFY_DIALOG_CANCEL "ecdg_bd_verify_password_dialog_cancel" - -#define HILDON_GET_PASSWORD_DIALOG_MAX_CHARS "ckdg_ib_maximum_characters_reached" - -static GtkDialogClass* parent_class; - -static void -hildon_get_password_dialog_class_init (HildonGetPasswordDialogClass *class); - -static void -hildon_get_password_dialog_init (HildonGetPasswordDialog *widget); - -static void -hildon_get_password_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_get_password_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static void -create_contents (HildonGetPasswordDialog *dialog); - -#ifdef MAEMO_GTK -static void -invalid_input (GtkWidget *widget, - GtkInvalidInputType reason, - gpointer unused); -#endif - -enum -{ - PROP_0, - PROP_MESSAGE, - PROP_PASSWORD, - PROP_NUMBERS_ONLY, - PROP_CAPTION_LABEL, - PROP_MAX_CHARS, - PROP_GET_OLD -}; - -/* Private functions */ -static void -hildon_get_password_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonGetPasswordDialog *dialog = HILDON_GET_PASSWORD_DIALOG (object); - HildonGetPasswordDialogPrivate *priv; - - priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE (object); - g_assert (priv); - - switch (prop_id) { - - case PROP_MESSAGE: - /* Set label text representing password domain */ - gtk_label_set_text (priv->message_label, g_value_get_string (value)); - break; - - case PROP_PASSWORD: - gtk_entry_set_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->password_entry))), - g_value_get_string(value)); - break; - - case PROP_NUMBERS_ONLY: -#ifdef MAEMO_GTK - /* Set input mode for the password entry */ - g_object_set(G_OBJECT (gtk_bin_get_child GTK_BIN ((priv->password_entry))), - "hildon-input-mode", - (g_value_get_boolean (value) - ? HILDON_GTK_INPUT_MODE_NUMERIC - : HILDON_GTK_INPUT_MODE_FULL), - NULL); -#endif - break; - - case PROP_CAPTION_LABEL: - hildon_get_password_dialog_set_caption (dialog, g_value_get_string (value)); - break; - - case PROP_MAX_CHARS: - hildon_get_password_dialog_set_max_characters (dialog, g_value_get_int (value)); - break; - - case PROP_GET_OLD: - priv->get_old = g_value_get_boolean (value); - create_contents (dialog); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_get_password_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - HildonGetPasswordDialog *dialog = HILDON_GET_PASSWORD_DIALOG (object); - HildonGetPasswordDialogPrivate *priv; - const gchar *string; - gint max_length; -#ifdef MAEMO_GTK - gint input_mode; -#endif - - priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - switch (prop_id) { - - case PROP_MESSAGE: - string = gtk_label_get_text (priv->message_label); - g_value_set_string (value, string); - break; - - case PROP_PASSWORD: - string = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->password_entry)))); - g_value_set_string (value, string); - break; - - case PROP_NUMBERS_ONLY: -#ifdef MAEMO_GTK - /* This property is set if and only if the input mode - of the password entry has been set to numeric only */ - g_object_get (G_OBJECT (gtk_bin_get_child (GTK_BIN (priv->password_entry))), - "hildon-input-mode", &input_mode, NULL); - g_value_set_boolean (value, - (input_mode == HILDON_GTK_INPUT_MODE_NUMERIC)); -#else - g_value_set_boolean (value, FALSE); -#endif - break; - - case PROP_CAPTION_LABEL: - string = hildon_caption_get_label (priv->password_entry); - g_value_set_string (value, string); - break; - - case PROP_MAX_CHARS: - max_length = gtk_entry_get_max_length - (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->password_entry)))); - g_value_set_int (value, max_length); - break; - - case PROP_GET_OLD: - g_value_set_boolean (value, priv->get_old); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_get_password_dialog_class_init (HildonGetPasswordDialogClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - parent_class = g_type_class_peek_parent (class); - - /* Override virtual functions */ - object_class->set_property = hildon_get_password_set_property; - object_class->get_property = hildon_get_password_get_property; - - /* Install new properties */ - - /** - * HildonGetPasswordDialog:message: - * - * Optional message displayed to the user. - */ - g_object_class_install_property - (object_class, - PROP_MESSAGE, - g_param_spec_string ("message", - "Message", - "Set optional message", - NULL, - G_PARAM_READWRITE)); - - /** - * HildonGetPasswordDialog:password: - * - * Password field contents. - */ - g_object_class_install_property - (object_class, - PROP_PASSWORD, - g_param_spec_string ("password", - "Password", - "Password field", - "DEFAULT", - G_PARAM_READWRITE)); - - /** - * HildonGetPasswordDialog:numbers-only: - * - * If the password entry field is operating in numbers-only mode. - */ - g_object_class_install_property - (object_class, - PROP_NUMBERS_ONLY, - g_param_spec_boolean ("numbers-only", - "NumbersOnly", - "Set entry to accept only numeric values", - FALSE, - G_PARAM_READWRITE)); - - /** - * HildonGetPasswordDialog:caption-label: - * - * Caption label. - */ - g_object_class_install_property - (object_class, - PROP_CAPTION_LABEL, - g_param_spec_string ("caption-label", - "Caption Label", - "The text to be set as the caption label", - NULL, - G_PARAM_READWRITE)); - - /** - * HildonGetPasswordDialog:max-characters: - * - * Maximum characters than can be entered. - */ - g_object_class_install_property - (object_class, - PROP_MAX_CHARS, - g_param_spec_int ("max-characters", - "Maximum Characters", - "The maximum number of characters the password" - " dialog accepts", - G_MININT, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - /** - * HildonGetPasswordDialog:get-old: - * - * If the dialog is used to retrieve an old password or set a new one. - */ - g_object_class_install_property - (object_class, - PROP_GET_OLD, - g_param_spec_boolean ("get-old", - "Get Old Password", - "TRUE if dialog is a get old password dialog, " - "FALSE if dialog is a get password dialog", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - /* Install private structure */ - g_type_class_add_private (class, sizeof (HildonGetPasswordDialogPrivate)); -} - -static void -hildon_get_password_dialog_init (HildonGetPasswordDialog *dialog) -{ - /* Set initial properties for the dialog; the actual contents are - created once the 'get-old' property is set with g_object_new */ - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); -} - -static void -create_contents (HildonGetPasswordDialog *dialog) -{ - HildonGetPasswordDialogPrivate *priv; - GtkSizeGroup * group; - GtkWidget *control; - AtkObject *atk_aux = NULL; - - /* Cache private pointer for faster member access */ - priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - /* Sizegroup for captions */ - group = GTK_SIZE_GROUP (gtk_size_group_new - (GTK_SIZE_GROUP_HORIZONTAL)); - - /* Dialog title */ - gtk_window_set_title (GTK_WINDOW (dialog), - priv->get_old - ? _(HILDON_GET_PASSWORD_DIALOG_TITLE) - : _(HILDON_GET_PASSWORD_VERIFY_DIALOG_TITLE)); - - /* Optional password domain label */ - priv->message_label = GTK_LABEL (gtk_label_new (NULL)); - - /* Create buttons */ - gtk_dialog_add_button (GTK_DIALOG (dialog), - (priv->get_old - ? HILDON_GET_PASSWORD_DIALOG_OK - : HILDON_GET_PASSWORD_VERIFY_DIALOG_OK), - GTK_RESPONSE_OK); - - gtk_dialog_add_button (GTK_DIALOG (dialog), - (priv->get_old - ? _(HILDON_GET_PASSWORD_DIALOG_CANCEL) - : _(HILDON_GET_PASSWORD_VERIFY_DIALOG_CANCEL)), - GTK_RESPONSE_CANCEL); - - /* Create password text entry */ - control = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); - if ((atk_aux = gtk_widget_get_accessible(control))) - { - atk_object_set_name(atk_aux, "Passwd"); - } - - gtk_entry_set_width_chars (GTK_ENTRY (control), 20); - -#ifdef MAEMO_GTK - g_object_set (control, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL); -#endif - - gtk_entry_set_visibility (GTK_ENTRY(control), FALSE); - priv->password_entry = HILDON_CAPTION - (hildon_caption_new(group, - (priv->get_old - ? _(HILDON_GET_PASSWORD_DIALOG_PASSWORD) - : _(HILDON_GET_PASSWORD_VERIFY_DIALOG_PASSWORD)), - control, NULL, - HILDON_CAPTION_OPTIONAL)); - hildon_caption_set_separator (HILDON_CAPTION (priv->password_entry), ""); - - /* Do the basic layout */ - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - GTK_WIDGET (priv->message_label), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - GTK_WIDGET (priv->password_entry), FALSE, FALSE, 0); - gtk_widget_show_all (GTK_DIALOG (dialog)->vbox); - - /* Ensure group is freed when all its contents have been removed */ - g_object_unref (group); -} - -/** - * hildon_get_password_dialog_get_type: - * - * Returns GType for HildonGetPasswordDialog as produced by - * g_type_register_static(). - * - * Returns: HildonGetPasswordDialog type - */ -GType G_GNUC_CONST -hildon_get_password_dialog_get_type (void) -{ - static GType dialog_type = 0; - - if (! dialog_type) { - static const GTypeInfo dialog_info = { - sizeof (HildonGetPasswordDialogClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_get_password_dialog_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonGetPasswordDialog), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_get_password_dialog_init - }; - - dialog_type = g_type_register_static (GTK_TYPE_DIALOG, - "HildonGetPasswordDialog", - &dialog_info, 0); - } - return dialog_type; -} - -/** - * hildon_get_password_dialog_new: - * @parent: parent window; can be NULL - * @get_old: FALSE creates a new get password dialog and - * TRUE creates a new get old password dialog. That is, - * if the password to be obtained is the old password, - * this parameter is specified TRUE. - * - * Construct a new HildonGetPasswordDialog. - * - * Returns: a new #GtkWidget of type HildonGetPasswordDialog - */ -GtkWidget* -hildon_get_password_dialog_new (GtkWindow *parent, - gboolean get_old) -{ - HildonGetPasswordDialog *dialog = g_object_new - (HILDON_TYPE_GET_PASSWORD_DIALOG, - "get-old", get_old, NULL); - - if (parent != NULL) { - gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); - } - - return (GtkWidget *) dialog; -} - -/** - * hildon_get_password_dialog_new_with_default: - * @parent: parent window; can be NULL - * @password: a default password to be shown in password field - * @get_old: FALSE creates a new get password dialog and - * TRUE creates a new get old password dialog. That is, - * if the password to be obtained is the old password, - * this parameter is specified TRUE. - * - * - * Same as #hildon_get_password_dialog_new but with a default password - * in password field. - * - * Returns: a new #GtkWidget of type HildonGetPasswordDialog - */ -GtkWidget* -hildon_get_password_dialog_new_with_default (GtkWindow *parent, - const gchar *password, - gboolean get_old) -{ - GtkWidget *dialog; - - dialog = hildon_get_password_dialog_new (parent, get_old); - - if (password != NULL) - g_object_set (G_OBJECT (dialog), "password", password, NULL); - - return GTK_WIDGET (dialog); -} - -/** - * hildon_get_password_dialog_get_password: - * @dialog: pointer to HildonSetPasswordDialog - * - * Gets the currently entered password. The string should not be freed. - * - * Returns: current password entered by the user. - */ -const gchar* -hildon_get_password_dialog_get_password (HildonGetPasswordDialog *dialog) -{ - GtkEntry *entry1; - gchar *text1; - - HildonGetPasswordDialogPrivate *priv; - - g_return_val_if_fail (HILDON_IS_GET_PASSWORD_DIALOG (dialog), NULL); - priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - /* Retrieve the password entry widget */ - entry1 = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->password_entry))); - text1 = GTK_ENTRY (entry1)->text; - - return text1; -} - -/** - * hildon_get_password_dialog_set_message - * @dialog: the dialog - * @message: a custom message or some other descriptive text to be set - * - * Sets the optional descriptive text displayed at the top of the dialog. - */ -void -hildon_get_password_dialog_set_message (HildonGetPasswordDialog *dialog, - const gchar *message) -{ - HildonGetPasswordDialogPrivate *priv; - - g_return_if_fail (HILDON_IS_GET_PASSWORD_DIALOG (dialog)); - - priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - gtk_label_set_text (priv->message_label, message); - -} - -/** - * hildon_get_password_dialog_set_caption: - * @dialog: the dialog - * @new_caption: the text to be set as the caption label - * - * Sets the password entry field's neigbouring label. - */ -void -hildon_get_password_dialog_set_caption (HildonGetPasswordDialog *dialog, - const gchar *new_caption) -{ - HildonGetPasswordDialogPrivate *priv; - - g_return_if_fail (HILDON_IS_GET_PASSWORD_DIALOG (dialog)); - g_return_if_fail (new_caption != NULL); - - priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - hildon_caption_set_label (priv->password_entry, new_caption); -} - -/** - * hildon_get_password_dialog_set_max_characters: - * @dialog: the dialog - * @max_characters: the maximum number of characters the password dialog - * accepts - * - * sets the maximum number of characters allowed as the password - */ -void -hildon_get_password_dialog_set_max_characters (HildonGetPasswordDialog *dialog, - gint max_characters) -{ - HildonGetPasswordDialogPrivate *priv; - - g_return_if_fail (max_characters > 0); - g_return_if_fail (HILDON_IS_GET_PASSWORD_DIALOG (dialog)); - - priv = HILDON_GET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - /* Apply the given length to password entry */ - gtk_entry_set_max_length (GTK_ENTRY - (gtk_bin_get_child - GTK_BIN ((priv->password_entry))), - max_characters); - - /* FIXME There is a bug here -- the prev. signal needs to be - * disconnected before connecting the new signal. Besides, this - * should go into the constructor */ - -#ifdef MAEMO_GTK - /* Connect callback to show error banner if the limit is exceeded */ - g_signal_connect (GTK_ENTRY - (gtk_bin_get_child - GTK_BIN ((priv->password_entry))), - "invalid_input", - G_CALLBACK (invalid_input), - NULL - ); -#endif -} - -#ifdef MAEMO_GTK -/* Callback that gets called when maximum chars is reached in the entry */ -static void -invalid_input (GtkWidget *widget, - GtkInvalidInputType reason, - gpointer unused) -{ - if (reason == GTK_INVALID_INPUT_MAX_CHARS_REACHED) - { - hildon_banner_show_information (widget, NULL, _(HILDON_GET_PASSWORD_DIALOG_MAX_CHARS)); - } -} -#endif diff --git a/hildon/hildon-get-password-dialog.h b/hildon/hildon-get-password-dialog.h deleted file mode 100644 index e903940..0000000 --- a/hildon/hildon-get-password-dialog.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_GET_PASSWORD_DIALOG_H__ -#define __HILDON_GET_PASSWORD_DIALOG_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_GET_PASSWORD_DIALOG \ - (hildon_get_password_dialog_get_type()) - -#define HILDON_GET_PASSWORD_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_GET_PASSWORD_DIALOG, \ - HildonGetPasswordDialog)) - -#define HILDON_GET_PASSWORD_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), HILDON_TYPE_GET_PASSWORD_DIALOG, \ - HildonGetPasswordDialogClass)) - -#define HILDON_IS_GET_PASSWORD_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_GET_PASSWORD_DIALOG)) - -#define HILDON_IS_GET_PASSWORD_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_GET_PASSWORD_DIALOG)) - -typedef struct _HildonGetPasswordDialog HildonGetPasswordDialog; - -typedef struct _HildonGetPasswordDialogClass HildonGetPasswordDialogClass; - -struct _HildonGetPasswordDialog -{ - GtkDialog parent; -}; - -struct _HildonGetPasswordDialogClass -{ - GtkDialogClass parent_class; -}; - -GType G_GNUC_CONST -hildon_get_password_dialog_get_type (void); - -GtkWidget* -hildon_get_password_dialog_new (GtkWindow *parent, - gboolean get_old); - -GtkWidget* -hildon_get_password_dialog_new_with_default (GtkWindow *parent, - const gchar *password, - gboolean get_old); - -void -hildon_get_password_dialog_set_message (HildonGetPasswordDialog *dialog, - const gchar *message); - -void -hildon_get_password_dialog_set_caption (HildonGetPasswordDialog *dialog, - const gchar *new_caption); - -void -hildon_get_password_dialog_set_max_characters (HildonGetPasswordDialog *dialog, - gint max_characters); - -const gchar* -hildon_get_password_dialog_get_password (HildonGetPasswordDialog *dialog); - -G_END_DECLS - -#endif /* __HILDON_GET_PASSWORD_DIALOG_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-helper.c b/hildon/hildon-helper.c index 76b6596..f07355b 100644 --- a/hildon/hildon-helper.c +++ b/hildon/hildon-helper.c @@ -31,8 +31,6 @@ * on widget styles and probing functions for touch events. */ -#undef HILDON_DISABLE_DEPRECATED - #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -343,96 +341,6 @@ hildon_helper_set_logical_font (GtkWidget *widget, return signum; } -static GQuark -hildon_helper_insensitive_message_quark (void) -{ - static GQuark quark = 0; - - if (G_UNLIKELY (quark == 0)) - quark = g_quark_from_static_string ("hildon-insensitive-message"); - - return quark; -} - -static void -show_insensitive_message (GtkWidget *widget, - gpointer user_data) -{ - gchar *message = NULL; - - g_assert (GTK_IS_WIDGET (widget)); - - message = (gchar*) g_object_get_qdata (G_OBJECT (widget), - hildon_helper_insensitive_message_quark ()); - - if (message) - hildon_banner_show_information (widget, NULL, message); -} - - -/** - * hildon_helper_set_insensitive_message: - * @widget: A #GtkWidget to assign a banner to - * @message: A message to display to the user - * - * This function assigns an insensitive message to a @widget. When the @widget is - * in an insensitive state and the user activates it, the @message will be displayed - * using a standard #HildonBanner. - * - * Deprecated: As of hildon 2.2, it is strongly discouraged to use insensitive messages. - **/ -void -hildon_helper_set_insensitive_message (GtkWidget *widget, - const gchar *message) -{ - g_return_if_fail (GTK_IS_WIDGET (widget)); - - /* Clean up any previous instance of the insensitive message */ - g_signal_handlers_disconnect_matched (G_OBJECT (widget), G_SIGNAL_MATCH_FUNC, - 0, 0, NULL, - G_CALLBACK (show_insensitive_message), NULL); - - /* We need to dup the string because the pointer might not be valid when the - insensitive-press signal callback is executed */ - g_object_set_qdata_full (G_OBJECT (widget), hildon_helper_insensitive_message_quark (), - (gpointer)g_strdup (message), - g_free); - - if (message != NULL) { - g_signal_connect (G_OBJECT (widget), "insensitive-press", - G_CALLBACK (show_insensitive_message), NULL); - } -} - -/** - * hildon_helper_set_insensitive_messagef: - * @widget: A #GtkWidget to assign a banner to - * @format: a printf-like format string - * @Varargs: arguments for the format string - * - * A version of hildon_helper_set_insensitive_message with string formatting. - * - * Deprecated: As of hildon 2.2, it is strongly discouraged to use insensitive messages. - **/ -void -hildon_helper_set_insensitive_messagef (GtkWidget *widget, - const gchar *format, - ...) -{ - g_return_if_fail (GTK_IS_WIDGET (widget)); - - gchar *message; - va_list args; - - va_start (args, format); - message = g_strdup_vprintf (format, args); - va_end (args); - - hildon_helper_set_insensitive_message (widget, message); - - g_free (message); -} - /** * hildon_helper_set_logical_color: * @widget: A #GtkWidget to assign this logical font for. diff --git a/hildon/hildon-helper.h b/hildon/hildon-helper.h index 77e344d..996b2a4 100644 --- a/hildon/hildon-helper.h +++ b/hildon/hildon-helper.h @@ -44,17 +44,6 @@ hildon_helper_set_logical_color (GtkWidget *widget, gboolean hildon_helper_event_button_is_finger (GdkEventButton *event); -#ifndef HILDON_DISABLE_DEPRECATED -void -hildon_helper_set_insensitive_message (GtkWidget *widget, - const gchar *message); - -void -hildon_helper_set_insensitive_messagef (GtkWidget *widget, - const gchar *format, - ...); -#endif - void hildon_helper_set_thumb_scrollbar (GtkScrolledWindow *win, gboolean thumb); diff --git a/hildon/hildon-hvolumebar.c b/hildon/hildon-hvolumebar.c deleted file mode 100644 index 3e1ff0e..0000000 --- a/hildon/hildon-hvolumebar.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-hvolumebar - * @short_description: A widget that displays a horizontal volume bar. - * @see_also: #HildonVVolumebar, #HildonVolumebar - * - * The #HildonHVolumebar widget displays a horizontal volume bar that allows - * increasing or decreasing volume within a pre-defined range, and includes - * a mute icon which users can click to mute the sound. - * - * <note> - * <para> - * #HildonHVolumeBar has been deprecated since Hildon 2.2 - * See <link linkend="hildon-migrating-volume-bar">Migrating Volume Bars</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <programlisting> - * GtkWidget *volbar = hildon_hvolumebar_new (); - * g_signal_connect (G_OBJECT(volbar), "mute_toggled", G_CALLBACK(mute_toggle), NULL); - * g_signal_connect (G_OBJECT(volbar), "level_changed", G_CALLBACK(level_change), NULL); - * </programlisting> - * </example> - * - */ - -#undef HILDON_DISABLE_DEPRECATED - -#include "hildon-hvolumebar.h" -#include "hildon-volumebar.h" -#include "hildon-volumebar-range.h" -#include "hildon-volumebar-private.h" - -/* Defines for normal version of HVolumebar */ -/* Toggle button */ - -#define DEFAULT_TBUTTON_WIDTH 60 - -#define DEFAULT_TBUTTON_HEIGHT 60 - -/* Volume bar */ -#define MINIMUM_BAR_WIDTH 147 - -#define DEFAULT_BAR_HEIGHT 60 - -#define DEFAULT_ENDING_SIZE 20 - -/* Gap to leave for mute button */ -#define VERTICAL_MUTE_GAP 0 - -#define HORIZONTAL_MUTE_GAP 0 - -/* Sizes inside a toolbar */ -/* Toggle button */ - -#define TOOL_DEFAULT_TBUTTON_WIDTH 26 - -#define TOOL_DEFAULT_TBUTTON_HEIGHT 26 - -/* Volumebar */ - -#define TOOL_MINIMUM_BAR_WIDTH 121 - -#define TOOL_DEFAULT_BAR_HEIGHT 40 - -#define TOOL_DEFAULT_ENDING_SIZE 0 - -#define TOOL_VERTICAL_MUTE_GAP \ - ((TOOL_DEFAULT_BAR_HEIGHT - TOOL_DEFAULT_TBUTTON_HEIGHT) / 2) - -static HildonVolumebarClass* parent_class; - -static void -hildon_hvolumebar_class_init (HildonHVolumebarClass *klass); - -static void -hildon_hvolumebar_init (HildonHVolumebar *hvolumebar); - -static gboolean -hildon_hvolumebar_expose (GtkWidget *widget, - GdkEventExpose *event); -static void -hildon_hvolumebar_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void -hildon_hvolumebar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void -hildon_hvolumebar_map (GtkWidget *widget); - -/** - * hildon_hvolumebar_get_type: - * - * Returns GType for HildonHVolumebar. - * - * Returns: HildonHVolumebar type - */ -GType G_GNUC_CONST -hildon_hvolumebar_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (HildonHVolumebarClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_hvolumebar_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonHVolumebar), - 0, - (GInstanceInitFunc) hildon_hvolumebar_init, - }; - type = g_type_register_static (HILDON_TYPE_VOLUMEBAR, - "HildonHVolumebar", &info, 0); - } - return type; -} - -static void -hildon_hvolumebar_class_init (HildonHVolumebarClass *klass) -{ - GtkWidgetClass *volumebar_class = GTK_WIDGET_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - - volumebar_class->size_request = hildon_hvolumebar_size_request; - volumebar_class->size_allocate = hildon_hvolumebar_size_allocate; - volumebar_class->map = hildon_hvolumebar_map; - volumebar_class->expose_event = hildon_hvolumebar_expose; -} - -static void -hildon_hvolumebar_init (HildonHVolumebar *hvolumebar) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE (hvolumebar); - - priv->volumebar = - HILDON_VOLUMEBAR_RANGE(hildon_volumebar_range_new - (GTK_ORIENTATION_HORIZONTAL)); - - gtk_widget_set_parent (GTK_WIDGET (priv->tbutton), GTK_WIDGET (hvolumebar)); - gtk_widget_set_parent (GTK_WIDGET (priv->volumebar), GTK_WIDGET (hvolumebar)); - - gtk_scale_set_draw_value (GTK_SCALE (priv->volumebar), FALSE); - - /* Signals */ - g_signal_connect_swapped (G_OBJECT (priv->volumebar), "value-changed", - G_CALLBACK(hildon_volumebar_level_change), - hvolumebar); - - g_signal_connect_swapped (priv->tbutton, "toggled", - G_CALLBACK (hildon_volumebar_mute_toggled), hvolumebar); - - gtk_widget_show (GTK_WIDGET (priv->volumebar)); -} - -/** - * hildon_hvolumebar_new: - * - * Creates a new #HildonHVolumebar widget. - * - * Returns: a new #HildonHVolumebar - */ -GtkWidget* -hildon_hvolumebar_new (void) -{ - return GTK_WIDGET (g_object_new(HILDON_TYPE_HVOLUMEBAR, NULL)); -} - -static void -hildon_hvolumebar_map (GtkWidget* widget) -{ - HildonVolumebarPrivate *priv; - GtkWidget *parent; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(widget); - g_assert (priv); - - parent = gtk_widget_get_ancestor (GTK_WIDGET (widget), GTK_TYPE_TOOLBAR); - - /* Check if the volumebar is in a toolbar */ - if (parent) - priv->is_toolbar = TRUE; - - GTK_WIDGET_CLASS (parent_class)->map (widget); -} - -static gboolean -hildon_hvolumebar_expose (GtkWidget * widget, - GdkEventExpose * event) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(HILDON_VOLUMEBAR(widget)); - g_assert (priv); - - if (GTK_WIDGET_DRAWABLE (widget)) { - /* Paint background */ - gtk_paint_box (widget->style, widget->window, - GTK_WIDGET_STATE (priv->volumebar), GTK_SHADOW_OUT, - NULL, widget, "background", - widget->allocation.x, - widget->allocation.y, - widget->allocation.width, - widget->allocation.height); - - /* The contents of the widget can paint themselves */ - /* FIXME Not sure if this is even needed here */ - (*GTK_WIDGET_CLASS(parent_class)->expose_event) (widget, event); - } - - return FALSE; -} - -static void -hildon_hvolumebar_size_request (GtkWidget * widget, - GtkRequisition * requisition) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(HILDON_VOLUMEBAR(widget)); - g_assert (priv); - - /* Volumebar has different dimensions in toolbar */ - requisition->width = (priv->is_toolbar - ? TOOL_MINIMUM_BAR_WIDTH - : MINIMUM_BAR_WIDTH); - - requisition->height = (priv->is_toolbar - ? TOOL_DEFAULT_BAR_HEIGHT - : DEFAULT_BAR_HEIGHT); -} - -static void -hildon_hvolumebar_size_allocate (GtkWidget * widget, - GtkAllocation * allocation) -{ - HildonVolumebarPrivate *priv; - GtkAllocation button_allocation, range_allocation; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(widget); - g_assert (priv); - - button_allocation.x = 0; - button_allocation.width = 0; - - /* Center the widget vertically */ - if (priv->is_toolbar && allocation->height > TOOL_DEFAULT_BAR_HEIGHT) { - allocation->y += (allocation->height - TOOL_DEFAULT_BAR_HEIGHT) / 2; - allocation->height = TOOL_DEFAULT_BAR_HEIGHT; - } - - if (!priv->is_toolbar && allocation->height > DEFAULT_BAR_HEIGHT) { - allocation->y += (allocation->height - DEFAULT_BAR_HEIGHT) / 2; - allocation->height = DEFAULT_BAR_HEIGHT; - } - - GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); - - if (priv->tbutton && GTK_WIDGET_VISIBLE (priv->tbutton)) { - - /* Allocate space for the mute button */ - if (priv->is_toolbar) { - button_allocation.x = allocation->x; - button_allocation.y = allocation->y + TOOL_VERTICAL_MUTE_GAP; - button_allocation.width = TOOL_DEFAULT_TBUTTON_WIDTH; - button_allocation.height = TOOL_DEFAULT_TBUTTON_HEIGHT; - } else { - button_allocation.x = allocation->x + DEFAULT_ENDING_SIZE; - button_allocation.y = allocation->y + VERTICAL_MUTE_GAP; - button_allocation.width = DEFAULT_TBUTTON_WIDTH; - button_allocation.height = DEFAULT_TBUTTON_HEIGHT; - } - gtk_widget_size_allocate (GTK_WIDGET (priv->tbutton), - &button_allocation); - } - if (priv->volumebar && GTK_WIDGET_VISIBLE (priv->volumebar)) { - - /* Allocate space for the slider */ - range_allocation.y = allocation->y; - - if (priv->tbutton && GTK_WIDGET_VISIBLE (priv->tbutton)) - { - /* Leave room for the mute button */ - range_allocation.x = button_allocation.x - + button_allocation.width - + HORIZONTAL_MUTE_GAP; - - if (priv->is_toolbar) - { - /* In toolbar with mute button */ - range_allocation.width = MAX(0, - allocation->width - - 2 * TOOL_DEFAULT_ENDING_SIZE - - TOOL_DEFAULT_TBUTTON_WIDTH - - HORIZONTAL_MUTE_GAP); - - range_allocation.height = TOOL_DEFAULT_BAR_HEIGHT; - - } - - else - { - /* Standalone with mute button */ - range_allocation.width = MAX(0, - allocation->width - - 2 * DEFAULT_ENDING_SIZE - - DEFAULT_TBUTTON_WIDTH - - HORIZONTAL_MUTE_GAP); - - range_allocation.height = DEFAULT_BAR_HEIGHT; - } - - } - - else - { - if (priv->is_toolbar) - { - /* In toolbar without mute button */ - range_allocation.x = allocation->x; - - range_allocation.width = MAX(0, - allocation->width - - 2 * TOOL_DEFAULT_ENDING_SIZE ); - - range_allocation.height = TOOL_DEFAULT_BAR_HEIGHT; - - } - - else - { - /* Standalone without mute button */ - range_allocation.x = allocation->x + DEFAULT_ENDING_SIZE; - - range_allocation.width = MAX(0, - allocation->width - - 2 * DEFAULT_ENDING_SIZE ); - - range_allocation.height = DEFAULT_BAR_HEIGHT; - } - } - - gtk_widget_size_allocate (GTK_WIDGET (priv->volumebar), - &range_allocation); - } -} - diff --git a/hildon/hildon-hvolumebar.h b/hildon/hildon-hvolumebar.h deleted file mode 100644 index 34017c7..0000000 --- a/hildon/hildon-hvolumebar.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_HVOLUMEBAR_H__ -#define __HILDON_HVOLUMEBAR_H__ - -#include "hildon-volumebar.h" - -G_BEGIN_DECLS - -#define HILDON_TYPE_HVOLUMEBAR (hildon_hvolumebar_get_type()) - -#define HILDON_HVOLUMEBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_HVOLUMEBAR, HildonHVolumebar)) - -#define HILDON_HVOLUMEBAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_HVOLUMEBAR, HildonHVolumebarClass)) - -#define HILDON_IS_HVOLUMEBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj,\ - HILDON_TYPE_HVOLUMEBAR)) - -#define HILDON_IS_HVOLUMEBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\ - HILDON_TYPE_HVOLUMEBAR)) - -#define HILDON_HVOLUMEBAR_GET_CLASS(obj) \ - ((HildonHVolumebarClass *) G_OBJECT_GET_CLASS(obj)) - -typedef struct _HildonHVolumebar HildonHVolumebar; - -typedef struct _HildonHVolumebarClass HildonHVolumebarClass; - -struct _HildonHVolumebar -{ - HildonVolumebar parent; -}; - -struct _HildonHVolumebarClass -{ - HildonVolumebarClass parent_class; -}; - -GType G_GNUC_CONST -hildon_hvolumebar_get_type (void); - -GtkWidget* -hildon_hvolumebar_new (void); - -G_END_DECLS - -#endif /* __HILDON_HVOLUMEBAR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-login-dialog-private.h b/hildon/hildon-login-dialog-private.h deleted file mode 100644 index 76e559c..0000000 --- a/hildon/hildon-login-dialog-private.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_NAME_PASSWORD_DIALOG_PRIVATE_H__ -#define __HILDON_NAME_PASSWORD_DIALOG_PRIVATE_H__ - -G_BEGIN_DECLS - -#define HILDON_LOGIN_DIALOG_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - HILDON_TYPE_LOGIN_DIALOG,\ - HildonLoginDialogPrivate)) - -typedef struct _HildonLoginDialogPrivate HildonLoginDialogPrivate; - -struct _HildonLoginDialogPrivate -{ - GtkLabel *message_label; - GtkWidget *username_entry; - GtkWidget *password_entry; -}; - -G_END_DECLS - -#endif /* __HILDON_NAME_PASSWORD_DIALOG_PRIVATE_H__ */ diff --git a/hildon/hildon-login-dialog.c b/hildon/hildon-login-dialog.c deleted file mode 100644 index 4f4f150..0000000 --- a/hildon/hildon-login-dialog.c +++ /dev/null @@ -1,431 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006, 2009 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-login-dialog - * @short_description: A widget which allows a user to enter an username - * and a password. - * @see_also: #HildonGetPasswordDialog, #HildonSetPasswordDialog - * - * #HildonLoginDialog is used to enter a username and password - * when accessing a password protected area. The widget performs no - * input checking and is used only for retrieving the username and a - * password. - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <errno.h> -#include <string.h> -#include <strings.h> -#include <unistd.h> -#include <stdio.h> -#include <libintl.h> -#include <glib.h> - -#include "hildon-login-dialog.h" -#include "hildon-caption.h" -#include "hildon-login-dialog-private.h" -#include "hildon-entry.h" -#include "hildon-stock.h" - -enum -{ - PROP_0, - PROP_MESSAGE, - PROP_USERNAME, - PROP_PASSWORD -}; - -static void -hildon_login_dialog_class_init (HildonLoginDialogClass *class); - -static void -hildon_login_dialog_init (HildonLoginDialog *widget); - -static void -hildon_login_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_login_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -#define HILDON_LOGIN_DIALOG_TITLE "frw_ti_get_user_name_and_pwd" - -#define HILDON_LOGIN_DIALOG_USERNAME "frw_ti_get_user_name_and_pwd_enter_user_name" - -#define HILDON_LOGIN_DIALOG_PASSWORD "frw_ti_get_user_name_and_pwd_enter_pwd" - -#define HILDON_LOGIN_DIALOG_OK HILDON_STOCK_DONE - -#define _(String) dgettext("hildon-libs", String) - -static GtkDialogClass* parent_class; - -/** - * hildon_login_dialog_get_type: - * - * Returns GType for HildonLoginDialog. - * - * Returns: HildonLoginDialog type - */ -GType G_GNUC_CONST -hildon_login_dialog_get_type (void) -{ - static GType dialog_type = 0; - - if (! dialog_type) { - static const GTypeInfo dialog_info = { - sizeof (HildonLoginDialogClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_login_dialog_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(HildonLoginDialog), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_login_dialog_init - }; - dialog_type = g_type_register_static (GTK_TYPE_DIALOG, - "HildonLoginDialog", - &dialog_info, 0); - } - - return dialog_type; -} - -static void -hildon_login_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonLoginDialog *dialog = NULL; - HildonLoginDialogPrivate *priv = NULL; - - dialog = HILDON_LOGIN_DIALOG (object); - priv = HILDON_LOGIN_DIALOG_GET_PRIVATE(dialog); - g_assert (priv); - - switch (prop_id) { - - case PROP_MESSAGE: - /* Set the password message text */ - hildon_login_dialog_set_message (dialog, g_value_get_string (value)); - break; - - case PROP_USERNAME: - /* Set the current username displayed in the dialog */ - gtk_entry_set_text (GTK_ENTRY (priv->username_entry), g_value_get_string (value)); - break; - - case PROP_PASSWORD: - /* Set the currently entered password */ - gtk_entry_set_text (GTK_ENTRY (priv->password_entry), g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_login_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - HildonLoginDialog *dialog = NULL; - HildonLoginDialogPrivate *priv = NULL; - - dialog = HILDON_LOGIN_DIALOG (object); - priv = HILDON_LOGIN_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - switch (prop_id) { - - case PROP_MESSAGE: - g_value_set_string (value, gtk_label_get_text (priv->message_label)); - break; - - case PROP_USERNAME: - g_value_set_string (value, hildon_login_dialog_get_username (dialog)); - break; - - case PROP_PASSWORD: - g_value_set_string (value, hildon_login_dialog_get_password (dialog)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_login_dialog_class_init (HildonLoginDialogClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - parent_class = g_type_class_peek_parent (class); - - /* Override virtual functions */ - object_class->set_property = hildon_login_dialog_set_property; - object_class->get_property = hildon_login_dialog_get_property; - - /* Install new properties */ - - /** - * HildonLoginDialog:message: - * - * Optional message displayed to the user. - */ - g_object_class_install_property (object_class, - PROP_MESSAGE, - g_param_spec_string ("message", - "Message", - "Message displayed by the dialog", - NULL, - G_PARAM_READWRITE)); - - /** - * HildonLoginDialog:username: - * - * Contents of the username field. - */ - g_object_class_install_property (object_class, - PROP_USERNAME, - g_param_spec_string ("username", - "Username", - "Username field", - "DEFAULT", - G_PARAM_READWRITE)); - - /** - * HildonLoginDialog:password: - * - * Contents of the password field. - */ - g_object_class_install_property (object_class, - PROP_PASSWORD, - g_param_spec_string ("password", - "Password", - "Password field", - "DEFAULT", - G_PARAM_READWRITE)); - - /* Install private data structure */ - g_type_class_add_private (class, sizeof (HildonLoginDialogPrivate)); -} - -static void -hildon_login_dialog_init (HildonLoginDialog *dialog) -{ - /* Access private structure */ - HildonLoginDialogPrivate *priv = HILDON_LOGIN_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - /* Size group for captions */ - GtkSizeGroup *group = GTK_SIZE_GROUP (gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL)); - HildonCaption *caption; - - /* Initialize dialog */ - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_window_set_title (GTK_WINDOW(dialog), _(HILDON_LOGIN_DIALOG_TITLE)); - - /* Optional message label */ - /* FIXME Set the warpping for the message label */ - priv->message_label = GTK_LABEL (gtk_label_new (NULL)); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - GTK_WIDGET (priv->message_label), FALSE, FALSE, 0); - - /* Create buttons */ - gtk_dialog_add_button (GTK_DIALOG (dialog), HILDON_STOCK_DONE, GTK_RESPONSE_OK); - - /* Setup username entry */ - priv->username_entry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); - -#ifdef MAEMO_GTK - g_object_set (priv->username_entry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL); -#endif - - caption = HILDON_CAPTION (hildon_caption_new - (group, - _(HILDON_LOGIN_DIALOG_USERNAME), - GTK_WIDGET (priv->username_entry), NULL, - HILDON_CAPTION_OPTIONAL)); - - hildon_caption_set_separator (caption, ""); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - GTK_WIDGET (caption), FALSE, FALSE, 0); - - /* Setup password entry */ - priv->password_entry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); - -#ifdef MAEMO_GTK - g_object_set (priv->password_entry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL); -#endif - - gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry), FALSE); - - caption = HILDON_CAPTION (hildon_caption_new (group, - _(HILDON_LOGIN_DIALOG_PASSWORD), - GTK_WIDGET (priv->password_entry), - NULL, - HILDON_CAPTION_OPTIONAL)); - - hildon_caption_set_separator (caption, ""); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - GTK_WIDGET (caption), FALSE, FALSE, 0); - - gtk_widget_show_all (GTK_DIALOG (dialog)->vbox); - gtk_widget_show_all (GTK_DIALOG (dialog)->action_area); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - - /* Ensure group is freed when all its contents have been removed */ - g_object_unref (group); -} - -/** - * hildon_login_dialog_new: - * @parent: the parent window of the dialog - * - * Creates a new #HildonLoginDialog widget with Ok and Close - * buttons. - * - * Returns: the newly created #HildonLoginDialog - */ -GtkWidget* -hildon_login_dialog_new (GtkWindow *parent) -{ - GtkWidget *self = g_object_new (HILDON_TYPE_LOGIN_DIALOG, NULL); - - if (parent) - gtk_window_set_transient_for (GTK_WINDOW (self), parent); - - return self; -} - -/** - * hildon_login_dialog_new_with_default: - * @parent: the parent window of the dialog - * @name: default username, NULL if unset - * @password: default password, NULL if unset - * - * Same as #hildon_login_dialog_new but with a - * default username and password. - * - * Returns: the newly created #HildonLoginDialog - */ -GtkWidget* -hildon_login_dialog_new_with_default (GtkWindow *parent, - const gchar *name, - const gchar *password) -{ - GtkWidget *self = hildon_login_dialog_new(parent); - - if (name != NULL) - g_object_set (G_OBJECT (self), "username", name, NULL); - - if (password != NULL) - g_object_set (G_OBJECT (self), "password", password, NULL); - - return self; -} - -/** - * hildon_login_dialog_get_username: - * @dialog: the dialog - * - * Gets the text that's in the username entry. - * - * Returns: a pointer to the name string. You should not modify it. - */ -const gchar* -hildon_login_dialog_get_username (HildonLoginDialog *dialog) -{ - HildonLoginDialogPrivate *priv; - - g_return_val_if_fail (HILDON_IS_LOGIN_DIALOG (dialog), NULL); - - priv = HILDON_LOGIN_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - return gtk_entry_get_text (GTK_ENTRY (priv->username_entry)); -} - -/** - * hildon_login_dialog_get_password: - * @dialog: the dialog - * - * Gets the text that's in the password entry. - * - * Returns: a pointer to the password string. You should not modify it. - */ -const gchar* -hildon_login_dialog_get_password (HildonLoginDialog *dialog) -{ - HildonLoginDialogPrivate *priv; - - g_return_val_if_fail (HILDON_IS_LOGIN_DIALOG (dialog), NULL); - - priv = HILDON_LOGIN_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - return gtk_entry_get_text (GTK_ENTRY (priv->password_entry)); -} - -/** - * hildon_login_dialog_set_message: - * @dialog: the dialog - * @msg: the message or some other descriptive text to be set - * - * Sets the optional descriptive text that is displayed on the top - * of the dialog. - */ -void -hildon_login_dialog_set_message (HildonLoginDialog *dialog, - const gchar *msg) -{ - HildonLoginDialogPrivate *priv; - - g_return_if_fail (HILDON_IS_LOGIN_DIALOG (dialog)); - - priv = HILDON_LOGIN_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - gtk_label_set_text (priv->message_label, msg); -} - - diff --git a/hildon/hildon-login-dialog.h b/hildon/hildon-login-dialog.h deleted file mode 100644 index bb5b440..0000000 --- a/hildon/hildon-login-dialog.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_NAME_PASSWORD_DIALOG_H__ -#define __HILDON_NAME_PASSWORD_DIALOG_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_LOGIN_DIALOG \ - (hildon_login_dialog_get_type ()) - -#define HILDON_LOGIN_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_LOGIN_DIALOG, \ - HildonLoginDialog)) - -#define HILDON_LOGIN_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), HILDON_TYPE_LOGIN_DIALOG, \ - HildonLoginDialogClass)) - -#define HILDON_IS_LOGIN_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_LOGIN_DIALOG)) - -#define HILDON_IS_LOGIN_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - HILDON_TYPE_LOGIN_DIALOG)) - -typedef struct _HildonLoginDialog HildonLoginDialog; - -typedef struct _HildonLoginDialogClass HildonLoginDialogClass; - -struct _HildonLoginDialog -{ - GtkDialog parent; -}; - -struct _HildonLoginDialogClass -{ - GtkDialogClass parent_class; -}; - -GType G_GNUC_CONST -hildon_login_dialog_get_type (void); - -GtkWidget* -hildon_login_dialog_new (GtkWindow *parent); - -GtkWidget* -hildon_login_dialog_new_with_default (GtkWindow *parent, - const gchar *name, - const gchar *password); - -const gchar* -hildon_login_dialog_get_username (HildonLoginDialog *dialog); - -const gchar* -hildon_login_dialog_get_password (HildonLoginDialog *dialog); - -void -hildon_login_dialog_set_message (HildonLoginDialog *dialog, - const gchar *msg); - -G_END_DECLS - -#endif /* __HILDON_LOGIN_DIALOG_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-note.c b/hildon/hildon-note.c index 698e9b5..00781e0 100644 --- a/hildon/hildon-note.c +++ b/hildon/hildon-note.c @@ -91,8 +91,6 @@ #include <X11/Xatom.h> #include <gdk/gdkx.h> -#undef HILDON_DISABLE_DEPRECATED - #include "hildon-note.h" #include "hildon-defines.h" #include "hildon-sound.h" @@ -186,8 +184,7 @@ event_box_press_event (GtkEventBox *event_box, { HildonNotePrivate *priv = HILDON_NOTE_GET_PRIVATE (note); - if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION || - priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) { + if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION) { gtk_dialog_response (note, GTK_RESPONSE_DELETE_EVENT); return TRUE; } else { @@ -304,21 +301,6 @@ hildon_note_get_property (GObject *object, } } -#ifdef MAEMO_GTK -static GObject * -hildon_note_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_params) -{ - GObject *object; - object = (* G_OBJECT_CLASS (parent_class)->constructor) - (type, n_construct_properties, construct_params); - hildon_note_set_padding (HILDON_NOTE (object)); - - return object; -} -#endif /* MAEMO_GTK */ - /** * hildon_note_get_type: * @@ -364,9 +346,6 @@ hildon_note_class_init (HildonNoteClass *class) object_class->finalize = hildon_note_finalize; object_class->set_property = hildon_note_set_property; object_class->get_property = hildon_note_get_property; -#ifdef MAEMO_GTK - object_class->constructor = hildon_note_constructor; -#endif /* MAEMO_GTK */ widget_class->realize = hildon_note_realize; widget_class->unrealize = hildon_note_unrealize; widget_class->size_request = hildon_note_size_request; @@ -400,36 +379,6 @@ hildon_note_class_init (HildonNoteClass *class) G_PARAM_READWRITE)); /** - * HildonNote:icon: - * - * Icon for the note. - * - * Deprecated: Since 2.2 - */ - g_object_class_install_property (object_class, - PROP_HILDON_NOTE_ICON, - g_param_spec_string ("icon", - "note icon", - "The name of the icon that appears in the note dialog", - "", - G_PARAM_READWRITE)); - - /** - * HildonNote:stock-icon: - * - * Stock icon name for the note. - * - * Deprecated: Since 2.2 - */ - g_object_class_install_property (object_class, - PROP_HILDON_NOTE_STOCK_ICON, - g_param_spec_string ("stock-icon", - "Stock note icon", - "The stock name of the icon that appears in the note dialog", - "", - G_PARAM_READWRITE)); - - /** * HildonNote:progressbar: * * If set, a #GtkProgressBar is displayed in the note. @@ -590,8 +539,7 @@ screen_size_changed (GdkScreen *screen, hildon_note_rename (HILDON_NOTE (note)); - if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION || - priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) { + if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION) { gint screen_width = gdk_screen_get_width (screen); gint text_width = screen_width - HILDON_INFORMATION_NOTE_MARGIN * 2; g_object_set (priv->label, "width-request", text_width, NULL); @@ -622,8 +570,7 @@ hildon_note_realize (GtkWidget *widget) display = gdk_drawable_get_display (widget->window); atom = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_NOTIFICATION_TYPE"); - if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION || - priv->note_n == HILDON_NOTE_TYPE_INFORMATION_THEME) { + if (priv->note_n == HILDON_NOTE_TYPE_INFORMATION) { notification_type = "_HILDON_NOTIFICATION_TYPE_INFO"; is_info_note = TRUE; } else { @@ -794,7 +741,6 @@ hildon_note_rebuild (HildonNote *note) gtk_widget_set_no_show_all (priv->cancelButton, FALSE); break; - case HILDON_NOTE_TYPE_INFORMATION_THEME: case HILDON_NOTE_TYPE_INFORMATION: #ifdef MAEMO_GTK gtk_dialog_set_padding (dialog, @@ -951,37 +897,6 @@ hildon_note_new_confirmation (GtkWindow *parent, } /** - * hildon_note_new_confirmation_with_icon_name: - * @parent: the parent window. The X window ID of the parent window - * has to be the same as the X window ID of the application. This is - * important so that the window manager could handle the windows - * correctly. In GTK the X window ID can be checked using - * GDK_WINDOW_XID(GTK_WIDGET(parent)->window). - * @description: the message to confirm - * @icon_name: icon to be displayed. If NULL, default icon is used. - * - * Create a new confirmation note. Confirmation note has a text (description) - * that you specify and two buttons. - * - * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set - * with this function will be ignored. Use hildon_note_new_confirmation() instead. - * - * Returns: a new #HildonNote. - */ -GtkWidget* -hildon_note_new_confirmation_with_icon_name (GtkWindow *parent, - const gchar *description, - const gchar *icon_name) -{ - GtkWidget *dialog; - - dialog = hildon_note_new_confirmation (parent, description); - g_object_set (dialog, "icon", icon_name, NULL); - - return dialog; -} - -/** * hildon_note_new_information: * @parent: the parent window. The X window ID of the parent window * has to be the same as the X window ID of the application. This is @@ -1005,7 +920,7 @@ hildon_note_new_information (GtkWindow *parent, dialog = g_object_new (HILDON_TYPE_NOTE, "note-type", - HILDON_NOTE_TYPE_INFORMATION_THEME, + HILDON_NOTE_TYPE_INFORMATION, "description", description, NULL); if (parent != NULL) @@ -1014,38 +929,6 @@ hildon_note_new_information (GtkWindow *parent, return dialog; } -/** - * hildon_note_new_information_with_icon_name: - * @parent: the parent window. The X window ID of the parent window - * has to be the same as the X window ID of the application. This is - * important so that the window manager could handle the windows - * correctly. In GTK the X window ID can be checked using - * GDK_WINDOW_XID(GTK_WIDGET(parent)->window). - * @description: the message to confirm. - * @icon_name: icon to be displayed. If %NULL, the default icon is used. - * - * Create a new information note. An information note has text (a description) - * that you specify, an OK button and an icon. - * - * Deprecated: Since 2.2, icons are not shown in confirmation notes. Icons set - * with this function will be ignored. Use hildon_note_new_information() - * instead. - * - * Returns: a new #HildonNote. - */ -GtkWidget* -hildon_note_new_information_with_icon_name (GtkWindow * parent, - const gchar *description, - const gchar *icon_name) -{ - GtkWidget *dialog; - - dialog = hildon_note_new_information (parent, description); - g_object_set (dialog, "icon", icon_name, NULL); - - return dialog; -} - /* FIXME This documentation string LIES! */ /** @@ -1166,7 +1049,6 @@ sound_handling (gpointer data) switch (priv->note_n) { case HILDON_NOTE_TYPE_INFORMATION: - case HILDON_NOTE_TYPE_INFORMATION_THEME: hildon_play_system_sound (INFORMATION_SOUND_PATH); break; diff --git a/hildon/hildon-note.h b/hildon/hildon-note.h index 6e8f67f..fd4d979 100644 --- a/hildon/hildon-note.h +++ b/hildon/hildon-note.h @@ -72,13 +72,6 @@ hildon_note_new_confirmation_add_buttons (GtkWindow *parent, const gchar *description, ...); -#ifndef HILDON_DISABLE_DEPRECATED -GtkWidget* -hildon_note_new_confirmation_with_icon_name (GtkWindow *parent, - const gchar *description, - const gchar *icon_name); -#endif - GtkWidget* hildon_note_new_cancel_with_progress_bar (GtkWindow *parent, const gchar *description, @@ -87,12 +80,6 @@ hildon_note_new_cancel_with_progress_bar (GtkWindow *parent, GtkWidget* hildon_note_new_information (GtkWindow *parent, const gchar *description); -#ifndef HILDON_DISABLE_DEPRECATED -GtkWidget* -hildon_note_new_information_with_icon_name (GtkWindow *parent, - const gchar *description, - const gchar *icon_name); -#endif void hildon_note_set_button_text (HildonNote *note, @@ -110,8 +97,6 @@ hildon_note_set_button_texts (HildonNote *note, * @HILDON_NOTE_TYPE_CONFIRMATION_BUTTON: Confirmation note with * custom buttons. * @HILDON_NOTE_TYPE_INFORMATION: Information note with an 'OK' button. - * @HILDON_NOTE_TYPE_INFORMATION_THEME: Deprecated information note with a themed - * icon. Equivalent to %HILDON_NOTE_TYPE_INFORMATION. * @HILDON_NOTE_TYPE_PROGRESSBAR: Note with a #GtkProgressBar and an 'OK' button. * * Type of a #HildonNote, defining its behavior, contents, and theming. @@ -121,7 +106,6 @@ typedef enum HILDON_NOTE_TYPE_CONFIRMATION = 0, HILDON_NOTE_TYPE_CONFIRMATION_BUTTON, HILDON_NOTE_TYPE_INFORMATION, - HILDON_NOTE_TYPE_INFORMATION_THEME, HILDON_NOTE_TYPE_PROGRESSBAR } HildonNoteType; diff --git a/hildon/hildon-number-editor-private.h b/hildon/hildon-number-editor-private.h deleted file mode 100644 index cabec13..0000000 --- a/hildon/hildon-number-editor-private.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_NUMBER_EDITOR_PRIVATE_H__ -#define __HILDON_NUMBER_EDITOR_PRIVATE_H__ - -G_BEGIN_DECLS - -typedef struct _HildonNumberEditorPrivate HildonNumberEditorPrivate; - -#define HILDON_NUMBER_EDITOR_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_NUMBER_EDITOR, \ - HildonNumberEditorPrivate)); - -struct _HildonNumberEditorPrivate -{ - /* Child widgets */ - GtkWidget *num_entry; - GtkWidget *plus; - GtkWidget *minus; - - gint start; /* Minimum */ - gint end; /* Maximum */ - gint default_val; - gint button_type; /* Type of button pressed: 1 = plus, -1 = minus */ - - /* Timer IDs */ - guint button_event_id; /* Repeat change when button is held */ - guint select_all_idle_id; /* Selection repaint hack - see hildon_number_editor_select_all */ -}; - -G_END_DECLS - -#endif /* __HILDON_NUMBER_EDITOR_PRIVATE_H__ */ diff --git a/hildon/hildon-number-editor.c b/hildon/hildon-number-editor.c deleted file mode 100644 index a8f57f7..0000000 --- a/hildon/hildon-number-editor.c +++ /dev/null @@ -1,1049 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-number-editor - * @short_description: A widget used to enter a number within a pre-defined range. - * - * HildonNumberEditor is used to enter a number from a specific range. - * There are two buttons to scroll the value in number field. - * Manual input is also possible. - * - * <note> - * <para> - * #HildonNumberEditor has been deprecated since Hildon 2.2 - * See <link linkend="hildon-migrating-number-widgets">Migrating Number Widgets</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <title>HildonNumberEditor example</title> - * <programlisting> - * number_editor = hildon_number_editor_new (-250, 500); - * hildon_number_editor_set_range (number_editor, 0, 100); - * </programlisting> - * </example> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <libintl.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-number-editor.h" -#include "hildon-marshalers.h" -#include "hildon-defines.h" -#include "hildon-enum-types.h" -#include "hildon-banner.h" -#include "hildon-number-editor-private.h" -#include "hildon-private.h" - -#define _(String) dgettext("hildon-libs", String) - -/*Pixel spec defines*/ -#define NUMBER_EDITOR_HEIGHT 30 - -/* Size of plus and minus buttons */ -#define BUTTON_HEIGHT 30 - -#define BUTTON_WIDTH 30 - -static void -hildon_number_editor_class_init (HildonNumberEditorClass *editor_class); - -static void -hildon_number_editor_init (HildonNumberEditor *editor); - -static gboolean -hildon_number_editor_entry_focusout (GtkWidget *widget, - GdkEventFocus *event, - gpointer data); - -static void -hildon_number_editor_entry_changed (GtkWidget *widget, - gpointer data); - -static void -hildon_number_editor_size_request (GtkWidget *widget, - GtkRequisition *requisition); - -static void -set_widget_allocation (GtkWidget *widget, - GtkAllocation *alloc, - const GtkAllocation *allocation); - -static void -hildon_number_editor_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static gboolean -hildon_number_editor_focus (GtkWidget *widget, - GtkDirectionType direction); - -static gboolean -hildon_number_editor_entry_keypress (GtkWidget *widget, - GdkEventKey *event, - gpointer data); - -static gboolean -hildon_number_editor_button_pressed (GtkWidget *widget, - GdkEventButton *event, - gpointer data); - -static gboolean -hildon_number_editor_entry_button_released (GtkWidget *widget, - GdkEventButton *event, - gpointer data); -static gboolean -hildon_number_editor_button_released (GtkWidget *widget, - GdkEvent *event, - HildonNumberEditor *editor); -static gboolean -do_mouse_timeout (HildonNumberEditor *editor); - -static void -change_numbers (HildonNumberEditor *editor, - gint update); - -static void -hildon_number_editor_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void -hildon_number_editor_destroy (GtkObject *self); - -static gboolean -hildon_number_editor_start_timer (HildonNumberEditor *editor); - -static void -hildon_number_editor_finalize (GObject *self); - -static gboolean -hildon_number_editor_range_error (HildonNumberEditor *editor, - HildonNumberEditorErrorType type); - -static gboolean -hildon_number_editor_select_all (HildonNumberEditorPrivate *priv); - -static void -hildon_number_editor_validate_value (HildonNumberEditor *editor, - gboolean allow_intermediate); - -static void -hildon_number_editor_set_property (GObject * object, - guint prop_id, - const GValue * value, - GParamSpec * pspec); - -static void -hildon_number_editor_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec * pspec); - -enum -{ - RANGE_ERROR, - LAST_SIGNAL -}; - -enum { - PROP_0, - PROP_VALUE -}; - -static GtkContainerClass* parent_class; - -static guint HildonNumberEditor_signal[LAST_SIGNAL] = {0}; - -/** - * hildon_number_editor_get_type: - * - * Returns GType for HildonNumberEditor. - * - * Returns: HildonNumberEditor type - */ -GType G_GNUC_CONST -hildon_number_editor_get_type (void) -{ - static GType editor_type = 0; - - if (!editor_type) - { - static const GTypeInfo editor_info = - { - sizeof (HildonNumberEditorClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_number_editor_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonNumberEditor), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_number_editor_init, - }; - editor_type = g_type_register_static (GTK_TYPE_CONTAINER, - "HildonNumberEditor", - &editor_info, 0); - } - return editor_type; -} - -static void -hildon_number_editor_class_init (HildonNumberEditorClass *editor_class) -{ - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (editor_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (editor_class); - GObjectClass *gobject_class = G_OBJECT_CLASS (editor_class); - - g_type_class_add_private (editor_class, - sizeof (HildonNumberEditorPrivate)); - - parent_class = g_type_class_peek_parent (editor_class); - - widget_class->size_request = hildon_number_editor_size_request; - widget_class->size_allocate = hildon_number_editor_size_allocate; - widget_class->focus = hildon_number_editor_focus; - - editor_class->range_error = hildon_number_editor_range_error; - - /* Because we derived our widget from GtkContainer, we should override - forall method */ - container_class->forall = hildon_number_editor_forall; - GTK_OBJECT_CLASS(editor_class)->destroy = hildon_number_editor_destroy; - gobject_class->finalize = hildon_number_editor_finalize; - gobject_class->set_property = hildon_number_editor_set_property; - gobject_class->get_property = hildon_number_editor_get_property; - - /** - * HildonNumberEditor:value: - * - * The current value of the number editor. - */ - g_object_class_install_property (gobject_class, PROP_VALUE, - g_param_spec_int ("value", - "Value", - "The current value of number editor", - G_MININT, - G_MAXINT, - 0, G_PARAM_READWRITE)); - - HildonNumberEditor_signal[RANGE_ERROR] = - g_signal_new ("range_error", HILDON_TYPE_NUMBER_EDITOR, - G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET - (HildonNumberEditorClass, range_error), - g_signal_accumulator_true_handled, NULL, - _hildon_marshal_BOOLEAN__ENUM, - G_TYPE_BOOLEAN, 1, HILDON_TYPE_NUMBER_EDITOR_ERROR_TYPE); -} - -static void -hildon_number_editor_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - HildonNumberEditorPrivate *priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (container); - - g_assert (callback != NULL); - g_assert (priv); - - if (! include_internals) - return; - - /* Enumerate child widgets */ - (*callback) (priv->minus, callback_data); - (*callback) (priv->num_entry, callback_data); - (*callback) (priv->plus, callback_data); -} - -static void -hildon_number_editor_destroy (GtkObject *self) -{ - HildonNumberEditorPrivate *priv; - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (self); - g_assert (priv); - - /* Free child widgets */ - if (priv->minus) - { - gtk_widget_unparent (priv->minus); - priv->minus = NULL; - } - if (priv->num_entry) - { - gtk_widget_unparent (priv->num_entry); - priv->num_entry = NULL; - } - if (priv->plus) - { - gtk_widget_unparent (priv->plus); - priv->plus = NULL; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - GTK_OBJECT_CLASS (parent_class)->destroy(self); -} - -static void -hildon_number_editor_stop_repeat_timer (HildonNumberEditorPrivate *priv) -{ - g_assert (priv != NULL); - - if (priv->button_event_id) - { - g_source_remove (priv->button_event_id); - priv->button_event_id = 0; - } -} - -static void -hildon_number_editor_finalize (GObject *self) -{ - HildonNumberEditorPrivate *priv; - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (self); - g_assert (priv); - - /* Free timers */ - hildon_number_editor_stop_repeat_timer (priv); - - if (priv->select_all_idle_id) - g_source_remove (priv->select_all_idle_id); - - /* Call parent class finalize, if have one */ - if (G_OBJECT_CLASS (parent_class)->finalize) - G_OBJECT_CLASS (parent_class)->finalize(self); -} - -static void -hildon_number_editor_init (HildonNumberEditor *editor) -{ - HildonNumberEditorPrivate *priv; - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - GTK_WIDGET_SET_FLAGS (GTK_WIDGET (editor), GTK_NO_WINDOW); - - /* Create child widgets */ - priv->num_entry = gtk_entry_new (); - priv->minus = gtk_button_new (); - priv->plus = gtk_button_new (); - - gtk_widget_set_name (priv->minus, "ne-minus-button"); - gtk_widget_set_name (priv->plus, "ne-plus-button" ); - gtk_widget_set_size_request (priv->minus, BUTTON_WIDTH, BUTTON_HEIGHT); - gtk_widget_set_size_request (priv->plus, BUTTON_WIDTH, BUTTON_HEIGHT); - gtk_entry_set_alignment (GTK_ENTRY(priv->num_entry), 1); - - GTK_WIDGET_UNSET_FLAGS (priv->minus, GTK_CAN_FOCUS); - GTK_WIDGET_UNSET_FLAGS (priv->plus, GTK_CAN_FOCUS); - - priv->button_event_id = 0; - priv->select_all_idle_id = 0; - - gtk_widget_set_parent (priv->minus, GTK_WIDGET (editor)); - gtk_widget_set_parent (priv->num_entry, GTK_WIDGET (editor)); - gtk_widget_set_parent (priv->plus, GTK_WIDGET (editor)); - - /* Connect child widget signals */ - g_signal_connect (GTK_OBJECT (priv->num_entry), "changed", - G_CALLBACK (hildon_number_editor_entry_changed), - editor); - - g_signal_connect (GTK_OBJECT (priv->num_entry), "focus-out-event", - G_CALLBACK (hildon_number_editor_entry_focusout), - editor); - - g_signal_connect (GTK_OBJECT (priv->num_entry), "key-press-event", - G_CALLBACK (hildon_number_editor_entry_keypress), - editor); - - g_signal_connect (GTK_OBJECT (priv->num_entry), "button-release-event", - G_CALLBACK (hildon_number_editor_entry_button_released), - NULL); - - g_signal_connect (GTK_OBJECT (priv->minus), "button-press-event", - G_CALLBACK (hildon_number_editor_button_pressed), - editor); - - g_signal_connect (GTK_OBJECT (priv->plus), "button-press-event", - G_CALLBACK (hildon_number_editor_button_pressed), - editor); - - g_signal_connect (GTK_OBJECT (priv->minus), "button-release-event", - G_CALLBACK (hildon_number_editor_button_released), - editor); - - g_signal_connect (GTK_OBJECT (priv->plus), "button-release-event", - G_CALLBACK (hildon_number_editor_button_released), - editor); - - g_signal_connect (GTK_OBJECT (priv->minus), "leave-notify-event", - G_CALLBACK(hildon_number_editor_button_released), - editor); - - g_signal_connect (GTK_OBJECT (priv->plus), "leave-notify-event", - G_CALLBACK (hildon_number_editor_button_released), - editor); - -#ifdef MAEMO_GTK - g_object_set (G_OBJECT (priv->num_entry), - "hildon-input-mode", HILDON_GTK_INPUT_MODE_NUMERIC, NULL); -#endif - - gtk_widget_show (priv->num_entry); - gtk_widget_show (priv->minus); - gtk_widget_show (priv->plus); - - hildon_number_editor_set_range (editor, G_MININT, G_MAXINT); -} - -static gboolean -hildon_number_editor_entry_button_released (GtkWidget *widget, - GdkEventButton *event, - gpointer data) -{ - gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1); - return FALSE; -} - -static gboolean -hildon_number_editor_button_released (GtkWidget *widget, - GdkEvent *event, - HildonNumberEditor *editor) -{ - HildonNumberEditorPrivate *priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - hildon_number_editor_stop_repeat_timer (priv); - return FALSE; -} - -/* Format given number to editor field, no checks performed, all signals - are sent normally. */ -static void -hildon_number_editor_real_set_value (HildonNumberEditorPrivate *priv, - gint value) -{ - gchar *buffer; - - /* Update text in entry to new value */ - buffer = g_strdup_printf ("%d", value); - gtk_entry_set_text (GTK_ENTRY (priv->num_entry), buffer); - g_free (buffer); -} - -static gboolean -hildon_number_editor_button_pressed (GtkWidget *widget, - GdkEventButton *event, - gpointer data) -{ - /* FIXME: XXX Why aren't we using hildon_number_editor_start_timer here? XXX */ - /* Need to fetch current value from entry and increment or decrement - it */ - - HildonNumberEditor *editor; - HildonNumberEditorPrivate *priv; - GtkSettings *settings; - guint timeout; - - g_assert (HILDON_IS_NUMBER_EDITOR (data)); - - editor = HILDON_NUMBER_EDITOR (data); - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - settings = gtk_settings_get_default (); - g_object_get (settings, "gtk-timeout-initial", &timeout, NULL); - - /* Save type of button pressed */ - if (GTK_BUTTON (widget) == GTK_BUTTON (priv->plus)) - priv->button_type = 1; - else - priv->button_type = -1; - - /* Start repetition timer */ - if (! priv->button_event_id) - { - change_numbers (editor, priv->button_type); - priv->button_event_id = gdk_threads_add_timeout (timeout, - (GSourceFunc) hildon_number_editor_start_timer, - editor); - } - - return FALSE; -} - -static gboolean -hildon_number_editor_start_timer (HildonNumberEditor *editor) -{ - HildonNumberEditorPrivate *priv; - GtkSettings *settings; - guint timeout; - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - settings = gtk_settings_get_default (); - g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL); - timeout *= 8; - - priv->button_event_id = gdk_threads_add_timeout (timeout, - (GSourceFunc) do_mouse_timeout, - editor); - - return FALSE; -} - -static gboolean -do_mouse_timeout (HildonNumberEditor *editor) -{ - HildonNumberEditorPrivate *priv; - g_assert (HILDON_IS_NUMBER_EDITOR (editor)); - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* Update value based on button held */ - change_numbers (editor, priv->button_type); - - return TRUE; -} - -/* Changes the current number value by the amount of update - and verifies the result. */ -static void -change_numbers (HildonNumberEditor *editor, - gint update) -{ - HildonNumberEditorPrivate *priv; - gint current_value; - - g_assert (HILDON_IS_NUMBER_EDITOR (editor)); - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - current_value = hildon_number_editor_get_value (editor); - - /* We need to rerun validation by hand, since validation - done in "changed" callback allows intermediate values */ - hildon_number_editor_real_set_value (priv, current_value + update); - hildon_number_editor_validate_value (editor, FALSE); - g_object_notify (G_OBJECT (editor), "value"); -} - -static void -add_select_all_idle (HildonNumberEditorPrivate *priv) -{ - g_assert (priv); - - if (! priv->select_all_idle_id) - { - priv->select_all_idle_id = - gdk_threads_add_idle ((GSourceFunc) hildon_number_editor_select_all, priv); - } -} - -static void -hildon_number_editor_validate_value (HildonNumberEditor *editor, - gboolean allow_intermediate) -{ - HildonNumberEditorPrivate *priv; - gint error_code, fixup_value; - const gchar *text; - long value; - gchar *tail; - gboolean r; - - g_assert (HILDON_IS_NUMBER_EDITOR(editor)); - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - text = gtk_entry_get_text (GTK_ENTRY (priv->num_entry)); - error_code = -1; - fixup_value = priv->default_val; - - if (text && text[0]) - { - /* Try to convert entry text to number */ - value = strtol (text, &tail, 10); - - /* Check if conversion succeeded */ - if (tail[0] == 0) - { - /* Check if value is in allowed range. This is tricky in those - cases when user is editing a value. - For example: Range = [100, 500] and user have just inputted "4". - This should not lead into error message. Otherwise value is - resetted back to "100" and next "4" press will reset it back - and so on. */ - if (allow_intermediate) - { - /* We now have the following error cases: - * If inputted value as above maximum and - maximum is either positive or then maximum - negative and value is positive. - * If inputted value is below minimum and minimum - is negative or minumum positive and value - negative or zero. - In all other cases situation can be fixed just by - adding new numbers to the string. - */ - if (value > priv->end && (priv->end >= 0 || (priv->end < 0 && value >= 0))) - { - error_code = HILDON_NUMBER_EDITOR_ERROR_MAXIMUM_VALUE_EXCEED; - fixup_value = priv->end; - } - else if (value < priv->start && (priv->start < 0 || (priv->start >= 0 && value <= 0))) - { - error_code = HILDON_NUMBER_EDITOR_ERROR_MINIMUM_VALUE_EXCEED; - fixup_value = priv->start; - } - } - else - { - if (value > priv->end) { - error_code = HILDON_NUMBER_EDITOR_ERROR_MAXIMUM_VALUE_EXCEED; - fixup_value = priv->end; - } - else if (value < priv->start) { - error_code = HILDON_NUMBER_EDITOR_ERROR_MINIMUM_VALUE_EXCEED; - fixup_value = priv->start; - } - } - } - /* The only valid case when conversion can fail is when we - have plain '-', intermediate forms are allowed AND - minimum bound is negative */ - else if (! allow_intermediate || strcmp (text, "-") != 0 || priv->start >= 0) - error_code = HILDON_NUMBER_EDITOR_ERROR_ERRONEOUS_VALUE; - } - else if (! allow_intermediate) - error_code = HILDON_NUMBER_EDITOR_ERROR_ERRONEOUS_VALUE; - - if (error_code != -1) - { - /* If entry is empty and intermediate forms are nor allowed, - emit error signal */ - /* Change to default value */ - hildon_number_editor_set_value (editor, fixup_value); - g_signal_emit (editor, HildonNumberEditor_signal[RANGE_ERROR], 0, error_code, &r); - add_select_all_idle (priv); - } -} - -static void -hildon_number_editor_entry_changed (GtkWidget *widget, - gpointer data) -{ - g_assert (HILDON_IS_NUMBER_EDITOR (data)); - hildon_number_editor_validate_value (HILDON_NUMBER_EDITOR (data), TRUE); - g_object_notify (G_OBJECT (data), "value"); -} - -static void -hildon_number_editor_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - HildonNumberEditor *editor; - HildonNumberEditorPrivate *priv; - GtkRequisition req; - - editor = HILDON_NUMBER_EDITOR (widget); - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* Requested size is size of all child widgets plus border space */ - gtk_widget_size_request (priv->minus, &req); - requisition->width = req.width; - - gtk_widget_size_request (priv->num_entry, &req); - requisition->width += req.width; - - gtk_widget_size_request (priv->plus, &req); - requisition->width += req.width; - - requisition->width += HILDON_MARGIN_DEFAULT * 2; - - /* FIXME: XXX Height is fixed */ - requisition->height = NUMBER_EDITOR_HEIGHT; -} - -/* Update alloc->width so widget fits, update alloc->x to point to free space */ -static void -set_widget_allocation (GtkWidget *widget, - GtkAllocation *alloc, - const GtkAllocation *allocation) -{ - GtkRequisition child_requisition; - - gtk_widget_get_child_requisition (widget, &child_requisition); - - /* Fit to widget width */ - if (allocation->width + allocation->x > alloc->x + child_requisition.width) - alloc->width = child_requisition.width; - else - { - alloc->width = allocation->width - (alloc->x - allocation->x); - if (alloc->width < 0) - alloc->width = 0; - } - - gtk_widget_size_allocate (widget, alloc); - /* Update x position */ - alloc->x += alloc->width; -} - -static void -hildon_number_editor_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - HildonNumberEditor *editor; - HildonNumberEditorPrivate *priv; - GtkAllocation alloc; - - editor = HILDON_NUMBER_EDITOR (widget); - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - widget->allocation = *allocation; - - /* Add upper border */ - alloc.y = widget->allocation.y + widget->style->ythickness; - - /* Fix height */ - if (widget->allocation.height > NUMBER_EDITOR_HEIGHT) - { - alloc.height = NUMBER_EDITOR_HEIGHT - widget->style->ythickness * 2; - alloc.y += (widget->allocation.height - NUMBER_EDITOR_HEIGHT) / 2; - } - else - alloc.height = widget->allocation.height - widget->style->ythickness * 2; - - if (alloc.height < 0) - alloc.height = 0; - - /* Add left border */ - alloc.x = allocation->x + widget->style->xthickness; - - /* Allocate positions for widgets (left-to-right) */ - set_widget_allocation(priv->minus, &alloc, &widget->allocation); - alloc.x += HILDON_MARGIN_DEFAULT; - - set_widget_allocation(priv->num_entry, &alloc, &widget->allocation); - alloc.x += HILDON_MARGIN_DEFAULT; - - set_widget_allocation(priv->plus, &alloc, &widget->allocation); -} - -static gboolean -hildon_number_editor_focus (GtkWidget *widget, - GtkDirectionType direction) -{ - gboolean retval; - GtkDirectionType effective_direction; - - g_assert (HILDON_IS_NUMBER_EDITOR (widget)); - - retval = hildon_private_composite_focus (widget, direction, &effective_direction); - - if (retval == TRUE) - return GTK_WIDGET_CLASS (parent_class)->focus (widget, effective_direction); - else - return FALSE; -} - -static gboolean -hildon_number_editor_entry_focusout (GtkWidget *widget, - GdkEventFocus *event, - gpointer data) -{ - g_assert (HILDON_IS_NUMBER_EDITOR(data)); - - hildon_number_editor_validate_value (HILDON_NUMBER_EDITOR(data), FALSE); - return FALSE; -} - -static gboolean -hildon_number_editor_entry_keypress (GtkWidget *widget, - GdkEventKey *event, - gpointer data) -{ - GtkEditable *editable; - gint cursor_pos; - - g_assert (HILDON_IS_NUMBER_EDITOR (data)); - - editable = GTK_EDITABLE (widget); - cursor_pos = gtk_editable_get_position (editable); - - switch (event->keyval) - { - case GDK_Left: - /* If the cursor is on the left, try to decrement */ - if (cursor_pos == 0) { - change_numbers (HILDON_NUMBER_EDITOR (data), -1); - return TRUE; - } - break; - - case GDK_Right: - /* If the cursor is on the right, try to increment */ - if (cursor_pos >= g_utf8_strlen(gtk_entry_get_text (GTK_ENTRY (widget)), -1)) - { - change_numbers (HILDON_NUMBER_EDITOR (data), 1); - gtk_editable_set_position(editable, cursor_pos); - return TRUE; - } - break; - - default: - break; - }; - - return FALSE; -} - -static gboolean -hildon_number_editor_range_error (HildonNumberEditor *editor, - HildonNumberEditorErrorType type) -{ - - gint min, max; - gchar *err_msg = NULL; - HildonNumberEditorPrivate *priv; - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - min = priv->start; - max = priv->end; - - /* Construct error message */ - switch (type) - { - case HILDON_NUMBER_EDITOR_ERROR_MAXIMUM_VALUE_EXCEED: - err_msg = g_strdup_printf (_("ckct_ib_maximum_value"), max, max); - break; - - case HILDON_NUMBER_EDITOR_ERROR_MINIMUM_VALUE_EXCEED: - err_msg = g_strdup_printf (_("ckct_ib_minimum_value"), min, min); - break; - - case HILDON_NUMBER_EDITOR_ERROR_ERRONEOUS_VALUE: - err_msg = - g_strdup_printf (_("ckct_ib_set_a_value_within_range"), min, max); - break; - } - - /* Infoprint error */ - if (err_msg) - { - hildon_banner_show_information (GTK_WIDGET (GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET(editor), - GTK_TYPE_WINDOW))), NULL, err_msg); - g_free(err_msg); - } - - return TRUE; -} - -/** - * hildon_number_editor_new: - * @min: minimum accepted value - * @max: maximum accepted value - * - * Creates new number editor - * - * Returns: a new #HildonNumberEditor widget - */ -GtkWidget* -hildon_number_editor_new (gint min, - gint max) -{ - HildonNumberEditor *editor = g_object_new (HILDON_TYPE_NUMBER_EDITOR, NULL); - - /* Set user inputted range to editor */ - hildon_number_editor_set_range (editor, min, max); - - return GTK_WIDGET (editor); -} - -/** - * hildon_number_editor_set_range: - * @editor: a #HildonNumberEditor widget - * @min: minimum accepted value - * @max: maximum accepted value - * - * Sets accepted number range for editor - */ -void -hildon_number_editor_set_range (HildonNumberEditor *editor, - gint min, - gint max) -{ - HildonNumberEditorPrivate *priv; - gchar buffer_min[32], buffer_max[32]; - gint a, b; - - g_return_if_fail (HILDON_IS_NUMBER_EDITOR (editor)); - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* Set preferences */ - priv->start = MIN (min, max); - priv->end = MAX (min, max); - - /* Find maximum allowed length of value */ - g_snprintf (buffer_min, sizeof (buffer_min), "%d", min); - g_snprintf (buffer_max, sizeof (buffer_max), "%d", max); - a = strlen (buffer_min); - b = strlen (buffer_max); - - /* Set maximum size of entry */ - gtk_entry_set_width_chars (GTK_ENTRY (priv->num_entry), MAX (a, b)); - hildon_number_editor_set_value (editor, priv->start); -} - -/** - * hildon_number_editor_get_value: - * @editor: a #HildonNumberEditor - * - * Gets the current value of the number editor. - * - * Returns: the current value - */ -gint -hildon_number_editor_get_value (HildonNumberEditor *editor) -{ - HildonNumberEditorPrivate *priv; - - g_return_val_if_fail (HILDON_IS_NUMBER_EDITOR (editor), 0); - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - return atoi (gtk_entry_get_text (GTK_ENTRY (priv->num_entry))); -} - -/** - * hildon_number_editor_set_value: - * @editor: a #HildonNumberEditor - * @value: numeric value for number editor - * - * Sets numeric value for number editor - */ -void -hildon_number_editor_set_value (HildonNumberEditor *editor, - gint value) -{ - HildonNumberEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_NUMBER_EDITOR (editor)); - - priv = HILDON_NUMBER_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - g_return_if_fail (value <= priv->end); - g_return_if_fail (value >= priv->start); - - priv->default_val = value; - hildon_number_editor_real_set_value (priv, value); - g_object_notify (G_OBJECT(editor), "value"); -} - -/* When calling gtk_entry_set_text, the entry widget does things that can - * cause the whole widget to redraw. This redrawing is delayed and if any - * selections are made right after calling the gtk_entry_set_text the - * setting of the selection might seem to have no effect. - * - * If the selection is delayed with a lower priority than the redrawing, - * the selection should stick. Calling this function with g_idle_add should - * do it. - */ -static gboolean -hildon_number_editor_select_all (HildonNumberEditorPrivate *priv) -{ - gtk_editable_select_region (GTK_EDITABLE (priv->num_entry), 0, -1); - priv->select_all_idle_id = 0; - return FALSE; -} - -static void -hildon_number_editor_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonNumberEditor *editor; - - editor = HILDON_NUMBER_EDITOR (object); - - switch (prop_id) { - - case PROP_VALUE: - hildon_number_editor_set_value (editor, g_value_get_int (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -static void -hildon_number_editor_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - HildonNumberEditor *editor; - - editor = HILDON_NUMBER_EDITOR (object); - - switch (prop_id) { - - case PROP_VALUE: - g_value_set_int(value, hildon_number_editor_get_value (editor)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - diff --git a/hildon/hildon-number-editor.h b/hildon/hildon-number-editor.h deleted file mode 100644 index 9b46fb3..0000000 --- a/hildon/hildon-number-editor.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_NUMBER_EDITOR_H__ -#define __HILDON_NUMBER_EDITOR_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_NUMBER_EDITOR \ - (hildon_number_editor_get_type()) - -#define HILDON_NUMBER_EDITOR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_NUMBER_EDITOR, HildonNumberEditor)) - -#define HILDON_NUMBER_EDITOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), HILDON_TYPE_NUMBER_EDITOR, \ - HildonNumberEditorClass)) - -#define HILDON_IS_NUMBER_EDITOR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_NUMBER_EDITOR)) - -#define HILDON_IS_NUMBER_EDITOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_NUMBER_EDITOR)) - -#define HILDON_NUMBER_EDITOR_GET_CLASS(obj) \ - ((HildonNumberEditorClass *) G_OBJECT_GET_CLASS(obj)) - -typedef struct _HildonNumberEditor HildonNumberEditor; - -typedef struct _HildonNumberEditorClass HildonNumberEditorClass; - -struct _HildonNumberEditor -{ - GtkContainer parent; -}; - -typedef enum -{ - HILDON_NUMBER_EDITOR_ERROR_MAXIMUM_VALUE_EXCEED, - HILDON_NUMBER_EDITOR_ERROR_MINIMUM_VALUE_EXCEED, - HILDON_NUMBER_EDITOR_ERROR_ERRONEOUS_VALUE -} HildonNumberEditorErrorType; - -struct _HildonNumberEditorClass -{ - GtkContainerClass parent_class; - - gboolean (*range_error) (HildonNumberEditor *editor, HildonNumberEditorErrorType type); -}; - -GType G_GNUC_CONST -hildon_number_editor_get_type (void); - -GtkWidget* -hildon_number_editor_new (gint min, gint max); - -void -hildon_number_editor_set_range (HildonNumberEditor *editor, - gint min, - gint max); - -gint -hildon_number_editor_get_value (HildonNumberEditor *editor); - -void -hildon_number_editor_set_value (HildonNumberEditor *editor, - gint value); - -G_END_DECLS - -#endif /* __HILDON_NUMBER_EDITOR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-pannable-area.c b/hildon/hildon-pannable-area.c index 4f6d854..6db7a46 100644 --- a/hildon/hildon-pannable-area.c +++ b/hildon/hildon-pannable-area.c @@ -45,8 +45,6 @@ * vertical, horizontal and both panning directions. */ -#undef HILDON_DISABLE_DEPRECATED - #include <math.h> #if USE_CAIRO_SCROLLBARS == 1 #include <cairo.h> @@ -579,29 +577,6 @@ hildon_pannable_area_class_init (HildonPannableAreaClass * klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - /** - * HildonPannableArea:size-request-policy: - * - * Controls the size request policy of the widget. - * - * <warning><para> - * HildonPannableArea:size-request-policy is deprecated and should - * not be used in newly-written code. See - * hildon_pannable_area_set_size_request_policy() - * </para></warning> - * - * Deprecated: since 2.2 - */ - g_object_class_install_property (object_class, - PROP_SIZE_REQUEST_POLICY, - g_param_spec_enum ("size-request-policy", - "Size Requisition policy", - "Controls the size request policy of the widget.", - HILDON_TYPE_SIZE_REQUEST_POLICY, - HILDON_SIZE_REQUEST_MINIMUM, - G_PARAM_READWRITE| - G_PARAM_CONSTRUCT)); - g_object_class_install_property (object_class, PROP_HADJUSTMENT, g_param_spec_object ("hadjustment", @@ -1008,10 +983,6 @@ hildon_pannable_area_set_property (GObject * object, case PROP_LOW_FRICTION_MODE: priv->low_friction_mode = g_value_get_boolean (value); break; - case PROP_SIZE_REQUEST_POLICY: - hildon_pannable_area_set_size_request_policy (HILDON_PANNABLE_AREA (object), - g_value_get_enum (value)); - break; case PROP_CENTER_ON_CHILD_FOCUS: priv->center_on_child_focus = g_value_get_boolean (value); break; @@ -3640,78 +3611,6 @@ hildon_pannable_area_get_vadjustment (HildonPannableArea *area) /** - * hildon_pannable_area_get_size_request_policy: - * @area: A #HildonPannableArea. - * - * This function returns the current size request policy of the - * widget. That policy controls the way the size_request is done in - * the pannable area. Check - * hildon_pannable_area_set_size_request_policy() for a more detailed - * explanation. - * - * returns: the policy is currently being used in the widget - * #HildonSizeRequestPolicy. - * - * Since: 2.2 - * - * Deprecated: See hildon_pannable_area_set_size_request_policy() - **/ -HildonSizeRequestPolicy -hildon_pannable_area_get_size_request_policy (HildonPannableArea *area) -{ - HildonPannableAreaPrivate *priv; - - g_return_val_if_fail (HILDON_IS_PANNABLE_AREA (area), FALSE); - - priv = area->priv; - - return priv->size_request_policy; -} - -/** - * hildon_pannable_area_set_size_request_policy: - * @area: A #HildonPannableArea. - * @size_request_policy: One of the allowed #HildonSizeRequestPolicy - * - * This function sets the pannable area size request policy. That - * policy controls the way the size_request is done in the pannable - * area. Pannable can use the size request of its children - * (#HILDON_SIZE_REQUEST_CHILDREN) or the minimum size required for - * the area itself (#HILDON_SIZE_REQUEST_MINIMUM), the latter is the - * default. Recall this size depends on the scrolling policy you are - * requesting to the pannable area, if you set #GTK_POLICY_NEVER this - * parameter will not have any effect with - * #HILDON_SIZE_REQUEST_MINIMUM set. - * - * Since: 2.2 - * - * Deprecated: This method and the policy request is deprecated, DO - * NOT use it in future code, the only policy properly supported in - * gtk+ nowadays is the minimum size. Use gtk_window_set_default_size() - * or gtk_window_set_geometry_hints() with the proper size in your case - * to define the height of your dialogs. - **/ -void -hildon_pannable_area_set_size_request_policy (HildonPannableArea *area, - HildonSizeRequestPolicy size_request_policy) -{ - HildonPannableAreaPrivate *priv; - - g_return_if_fail (HILDON_IS_PANNABLE_AREA (area)); - - priv = area->priv; - - if (priv->size_request_policy == size_request_policy) - return; - - priv->size_request_policy = size_request_policy; - - gtk_widget_queue_resize (GTK_WIDGET (area)); - - g_object_notify (G_OBJECT (area), "size-request-policy"); -} - -/** * hildon_pannable_area_get_center_on_child_focus * @area: A #HildonPannableArea * diff --git a/hildon/hildon-pannable-area.h b/hildon/hildon-pannable-area.h index 51690e5..4181a4d 100644 --- a/hildon/hildon-pannable-area.h +++ b/hildon/hildon-pannable-area.h @@ -97,27 +97,6 @@ typedef enum { } HildonMovementDirection; /** - * HildonSizeRequestPolicy: - * @HILDON_SIZE_REQUEST_MINIMUM: The minimum size the widget could use - * to paint itself - * @HILDON_SIZE_REQUEST_CHILDREN: The minimum size of the children of - * the widget - * - * Used to control the size request policy of the widget - * - * Deprecated: This define and the policy request is deprecated, DO - * NOT use it in future code. Check - * #hildon_pannable_area_set_size_request_policy documentation for - * more information. - */ -#ifndef HILDON_DISABLE_DEPRECATED -typedef enum { - HILDON_SIZE_REQUEST_MINIMUM, - HILDON_SIZE_REQUEST_CHILDREN -} HildonSizeRequestPolicy; -#endif - -/** * HildonPannableArea: * * HildonPannableArea has no publicly accessible fields @@ -164,11 +143,6 @@ void hildon_pannable_area_jump_to_child (HildonPannableArea *area, GtkWidget *child); GtkWidget* hildon_pannable_get_child_widget_at (HildonPannableArea *area, gdouble x, gdouble y); -#ifndef HILDON_DISABLE_DEPRECATED -HildonSizeRequestPolicy hildon_pannable_area_get_size_request_policy (HildonPannableArea *area); -void hildon_pannable_area_set_size_request_policy (HildonPannableArea *area, - HildonSizeRequestPolicy size_request_policy); -#endif GtkAdjustment* hildon_pannable_area_get_hadjustment (HildonPannableArea *area); GtkAdjustment* hildon_pannable_area_get_vadjustment (HildonPannableArea *area); gboolean hildon_pannable_area_get_center_on_child_focus (HildonPannableArea *area); diff --git a/hildon/hildon-picker-dialog.h b/hildon/hildon-picker-dialog.h index 3d867f5..040b733 100644 --- a/hildon/hildon-picker-dialog.h +++ b/hildon/hildon-picker-dialog.h @@ -21,17 +21,7 @@ #ifndef __HILDON_PICKER_DIALOG_H__ #define __HILDON_PICKER_DIALOG_H__ -#ifdef HILDON_DISABLE_DEPRECATED - #define __SHOULD_REENABLE_DISABLE_DEPRECATED -#endif - -#undef HILDON_DISABLE_DEPRECATED #include "hildon-dialog.h" - -#ifdef __SHOULD_REENABLE_DISABLE_DEPRECATED - #define HILDON_DISABLE_DEPRECATED -#endif - #include "hildon-touch-selector.h" G_BEGIN_DECLS diff --git a/hildon/hildon-private.c b/hildon/hildon-private.c index ac16f39..6fc945e 100644 --- a/hildon/hildon-private.c +++ b/hildon/hildon-private.c @@ -22,64 +22,13 @@ * */ -#undef HILDON_DISABLE_DEPRECATED - #ifdef HAVE_CONFIG_H #include <config.h> #endif #include "hildon-private.h" -#include "hildon-date-editor.h" -#include "hildon-time-editor.h" #include "hildon-defines.h" -/* This function is a private function of hildon. It hadles focus - * changing for composite hildon widgets: HildonDateEditor, - * HildonNumberEditor, HildonTimeEditor, HildonWeekdayPicker. - * Its purpose is to focus the first widget (from left) inside the container - * regardless of where the focus is coming from. - */ -gboolean G_GNUC_INTERNAL -hildon_private_composite_focus (GtkWidget *widget, - GtkDirectionType direction, - GtkDirectionType *effective_direction) -{ - GtkWidget *toplevel = NULL; - GtkWidget *focus_widget = NULL; - gboolean coming_from_outside = FALSE; - - toplevel = gtk_widget_get_toplevel (widget); - - focus_widget = GTK_WINDOW (toplevel)->focus_widget; - - if (focus_widget == NULL || gtk_widget_is_ancestor (focus_widget, widget) == FALSE) - { - /* When coming from outside we want to give focus to the first - item in the widgets */ - *effective_direction = GTK_DIR_TAB_FORWARD; - coming_from_outside = TRUE; - } - else - *effective_direction = direction; - - switch (direction) { - case GTK_DIR_UP: - case GTK_DIR_DOWN: - case GTK_DIR_TAB_FORWARD: - case GTK_DIR_TAB_BACKWARD: - if ((HILDON_IS_DATE_EDITOR (widget) || HILDON_IS_TIME_EDITOR(widget)) && - !coming_from_outside) - return FALSE; - /* fall through */ - default: - return TRUE; - } - - g_assert_not_reached (); - return TRUE; -} - - G_GNUC_INTERNAL GtkWidget * hildon_private_create_animation (gfloat framerate, const gchar *template, @@ -129,7 +78,7 @@ hildon_gtk_window_set_clear_window_flag (GtkWindow * Atom xatom, gboolean flag) { - GdkWindow *gdkwin = GTK_WIDGET (window)->window; + GdkWindow *gdkwin = gtk_widget_get_window (GTK_WIDGET (window)) ; GdkAtom atom = gdk_atom_intern (atomname, FALSE); if (flag) { @@ -147,7 +96,7 @@ hildon_gtk_window_set_flag (GtkWindow gpointer userdata) { g_return_if_fail (GTK_IS_WINDOW (window)); - if (GTK_WIDGET_REALIZED (window)) { + if (gtk_widget_get_realized (GTK_WIDGET (window))) { (*func) (window, userdata); } else { g_signal_handlers_disconnect_matched (window, G_SIGNAL_MATCH_FUNC, diff --git a/hildon/hildon-private.h b/hildon/hildon-private.h index 53328e5..ed99173 100644 --- a/hildon/hildon-private.h +++ b/hildon/hildon-private.h @@ -31,15 +31,6 @@ G_BEGIN_DECLS -#ifndef HILDON_DISABLE_DEPRECATED - -gboolean G_GNUC_INTERNAL -hildon_private_composite_focus (GtkWidget *widget, - GtkDirectionType direction, - GtkDirectionType *effective_direction); - -#endif /* HILDON_DISABLE_DEPRECATED */ - G_GNUC_INTERNAL GtkWidget * hildon_private_create_animation (gfloat framerate, const gchar *template, diff --git a/hildon/hildon-program.c b/hildon/hildon-program.c index 441298d..e7d332f 100644 --- a/hildon/hildon-program.c +++ b/hildon/hildon-program.c @@ -76,8 +76,6 @@ * </example> */ -#undef HILDON_DISABLE_DEPRECATED - #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -265,46 +263,6 @@ hildon_program_get_property (GObject *object, } } -/** - * hildon_program_pop_window_stack: - * @self: A #HildonProgram - * - * Pops a window from the stack. - * - * Deprecated: Use hildon_window_stack_pop() instead - * - * Returns: A #HildonStackableWindow, or %NULL - * - * Since: 2.2 - */ -HildonStackableWindow * -hildon_program_pop_window_stack (HildonProgram *self) -{ - HildonWindowStack *stack = hildon_window_stack_get_default (); - GtkWidget *win = hildon_window_stack_pop_1 (stack); - g_warning ("%s: this function is deprecated. Use hildon_window_stack_pop() instead", __FUNCTION__); - return win ? HILDON_STACKABLE_WINDOW (win) : NULL; -} - -/** - * hildon_program_peek_window_stack: - * @self: A #HildonProgram - * - * Deprecated: Use hildon_window_stack_peek() instead - * - * Returns: A #HildonStackableWindow, or %NULL - * - * Since: 2.2 - */ -HildonStackableWindow * -hildon_program_peek_window_stack (HildonProgram *self) -{ - HildonWindowStack *stack = hildon_window_stack_get_default (); - GtkWidget *win = hildon_window_stack_peek (stack); - g_warning ("%s: this function is deprecated. Use hildon_window_stack_peek() instead", __FUNCTION__); - return win ? HILDON_STACKABLE_WINDOW (win) : NULL; -} - /* Utilities */ static gint hildon_program_window_list_compare (gconstpointer window_a, @@ -918,23 +876,3 @@ hildon_program_get_is_topmost (HildonProgram *self) return priv->is_topmost; } -/** - * hildon_program_go_to_root_window: - * @self: A #HildonProgram - * - * Goes to the root window of the stack. - * - * Deprecated: See #HildonWindowStack - * - * Since: 2.2 - */ -void -hildon_program_go_to_root_window (HildonProgram *self) -{ - HildonWindowStack *stack = hildon_window_stack_get_default (); - gint n = hildon_window_stack_size (stack); - g_warning ("%s: this function is deprecated. Use hildon_window_stack_pop() instead.", __FUNCTION__); - if (n > 1) { - hildon_window_stack_pop (stack, n-1, NULL); - } -} diff --git a/hildon/hildon-program.h b/hildon/hildon-program.h index a4d3210..db60538 100644 --- a/hildon/hildon-program.h +++ b/hildon/hildon-program.h @@ -117,17 +117,6 @@ hildon_program_get_common_toolbar (HildonProgram *self); gboolean hildon_program_get_is_topmost (HildonProgram *self); -#ifndef HILDON_DISABLE_DEPRECATED -HildonStackableWindow * -hildon_program_pop_window_stack (HildonProgram *self); - -HildonStackableWindow * -hildon_program_peek_window_stack (HildonProgram *self); - -void -hildon_program_go_to_root_window (HildonProgram *self); -#endif /* HILDON_DISABLE_DEPRECATED */ - G_END_DECLS #endif /* __HILDON_PROGRAM_H__ */ diff --git a/hildon/hildon-range-editor-private.h b/hildon/hildon-range-editor-private.h deleted file mode 100644 index d23d60e..0000000 --- a/hildon/hildon-range-editor-private.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_RANGE_EDITOR_PRIVATE_H__ -#define __HILDON_RANGE_EDITOR_PRIVATE_H__ - -G_BEGIN_DECLS - -#define HILDON_RANGE_EDITOR_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_RANGE_EDITOR, HildonRangeEditorPrivate)); - -typedef struct _HildonRangeEditorPrivate HildonRangeEditorPrivate; - -struct _HildonRangeEditorPrivate -{ - GtkWidget *start_entry; /* Entry for lower value */ - GtkWidget *end_entry; /* Entry for higher value */ - - GtkWidget *label; - - gint range_limits_start; /* Minimum value allowed for range start/end */ - gint range_limits_end; /* Maximum value allowed for range start/end */ - - gboolean bp; /* Button pressed, don't overwrite selection */ -}; - -G_END_DECLS - -#endif /* __HILDON_RANGE_EDITOR_PRIVATE_H__ */ diff --git a/hildon/hildon-range-editor.c b/hildon/hildon-range-editor.c deleted file mode 100644 index beb5322..0000000 --- a/hildon/hildon-range-editor.c +++ /dev/null @@ -1,1079 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-range-editor - * @short_description: A widget is used to ask bounds of a range. - * - * HidlonRangeEditor allows entering a pair of integers, e.g. the lower - * and higher bounds of a range. A minimum and maximum can also be set - * for the bounds. - * - * <note> - * <para> - * #HildonRangeEditor has been deprecated since Hildon 2.2 and should not - * be used in newly written code. See - * <link linkend="hildon-migrating-number-widgets">Migrating Number Widgets</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <programlisting> - * range_editor = hildon_range_editor_new (); - * hildon_range_editor_set_limits (editor, start, end ); - * hildon_range_editor_get_range (editor, &start, &end); - * </programlisting> - * </example> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <libintl.h> -#include <string.h> -#include <stdlib.h> -#include <glib/gprintf.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-range-editor.h" -#include "hildon-banner.h" -#include "hildon-range-editor-private.h" - -#define _(string) \ - dgettext("hildon-libs", string) - -/* Alignment in entry box ( 0 = left, 1 = right ) */ - -#define DEFAULT_ALIGNMENT 1 - -/* Amount of padding to add to each side of the separator */ - -#define DEFAULT_PADDING 3 - -#define DEFAULT_START -999 - -#define DEFAULT_END 999 - -#define DEFAULT_LENGTH 4 - -static GtkContainerClass *parent_class = NULL; - -static void -hildon_range_editor_class_init (HildonRangeEditorClass *editor_class); - -static void -hildon_range_editor_init (HildonRangeEditor *editor); - -static void -hildon_range_editor_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void -hildon_range_editor_destroy (GtkObject *self); - -static void -hildon_range_editor_size_request (GtkWidget *widget, - GtkRequisition *requisition); - -static void -hildon_range_editor_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static gboolean -hildon_range_editor_entry_focus_in (GtkEditable *editable, - GdkEventFocus *event, - HildonRangeEditor *editor); - -static gboolean -hildon_range_editor_entry_focus_out (GtkEditable *editable, - GdkEventFocus *event, - HildonRangeEditor *editor); - -static gboolean -hildon_range_editor_entry_keypress (GtkWidget *widget, - GdkEventKey *event, - HildonRangeEditor *editor); - -static gboolean -hildon_range_editor_released (GtkEditable *editable, - GdkEventButton *event, - HildonRangeEditor *editor); - -static gboolean -hildon_range_editor_press (GtkEditable *editable, - GdkEventButton *event, - HildonRangeEditor *editor); - -static void -hildon_range_editor_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_range_editor_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void -hildon_range_editor_entry_changed (GtkWidget *widget, - HildonRangeEditor *editor); - -enum -{ - PROP_0, - PROP_LOWER = 1, - PROP_HIGHER, - PROP_MIN, - PROP_MAX, - PROP_SEPARATOR -}; - -static void -hildon_range_editor_class_init (HildonRangeEditorClass *editor_class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (editor_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (editor_class); - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (editor_class); - - parent_class = g_type_class_peek_parent (editor_class); - - g_type_class_add_private (editor_class, sizeof (HildonRangeEditorPrivate)); - - gobject_class->set_property = hildon_range_editor_set_property; - gobject_class->get_property = hildon_range_editor_get_property; - widget_class->size_request = hildon_range_editor_size_request; - widget_class->size_allocate = hildon_range_editor_size_allocate; - - container_class->forall = hildon_range_editor_forall; - GTK_OBJECT_CLASS (editor_class)->destroy = hildon_range_editor_destroy; - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_int ("hildon_range_editor_entry_alignment", - "Hildon RangeEditor entry alignment", - "Hildon RangeEditor entry alignment", 0, 1, - DEFAULT_ALIGNMENT, - G_PARAM_READABLE)); - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_int ("hildon_range_editor_separator_padding", - "Hildon RangeEditor separator padding", - "Hildon RangeEditor separaror padding", - G_MININT, G_MAXINT, - DEFAULT_PADDING, - G_PARAM_READABLE)); - - /** - * HildonRangeEditor:min: - * - * Minimum value in a range. - * Default: -999 - */ - g_object_class_install_property (gobject_class, PROP_MIN, - g_param_spec_int ("min", - "Minimum value", - "Minimum value in a range", - G_MININT, G_MAXINT, - DEFAULT_START, G_PARAM_CONSTRUCT | - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - /** - * HildonRangeEditor:max: - * - * Maximum value in a range. - * Default: 999 - */ - g_object_class_install_property (gobject_class, PROP_MAX, - g_param_spec_int ("max", - "Maximum value", - "Maximum value in a range", - G_MININT, G_MAXINT, - DEFAULT_END, G_PARAM_CONSTRUCT | - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - /** - * HildonRangeEditor:lower: - * - * Current value in the entry presenting lower end of selected range. - * Default: -999 - */ - g_object_class_install_property (gobject_class, PROP_LOWER, - g_param_spec_int ("lower", - "Current lower value", - "Current value in the entry presenting lower end of selected range", - G_MININT, G_MAXINT, - DEFAULT_START, G_PARAM_CONSTRUCT | - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - /** - * HildonRangeEditor:higher: - * - * Current value in the entry presenting higher end of selected range. - * Default: 999 - */ - g_object_class_install_property (gobject_class, PROP_HIGHER, - g_param_spec_int ("higher", - "Current higher value", - "Current value in the entry presenting higher end of selected range", - G_MININT, G_MAXINT, - DEFAULT_END, G_PARAM_CONSTRUCT | - G_PARAM_READABLE | G_PARAM_WRITABLE)); - - /** - * HildonRangeEditor:separator: - * - * Separator string to separate range editor entries. - * Default: "-" - */ - g_object_class_install_property (gobject_class, PROP_SEPARATOR, - g_param_spec_string ("separator", - "Separator", - "Separator string to separate entries", - _("ckct_wi_range_separator"), - G_PARAM_CONSTRUCT | - G_PARAM_READABLE | G_PARAM_WRITABLE)); -} - -static void -hildon_range_editor_init (HildonRangeEditor *editor) -{ - HildonRangeEditorPrivate *priv; - - gint range_editor_entry_alignment; - gint range_editor_separator_padding; - - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - GTK_WIDGET_SET_FLAGS (editor, GTK_NO_WINDOW); - - gtk_widget_push_composite_child (); - - priv->start_entry = gtk_entry_new (); - priv->end_entry = gtk_entry_new (); - priv->label = gtk_label_new (_("ckct_wi_range_separator")); - priv->bp = FALSE; - - /* Get values from gtkrc (or use defaults) */ - /* FIXME: This is broken, styles are not yet attached */ - gtk_widget_style_get (GTK_WIDGET (editor), - "hildon_range_editor_entry_alignment", - &range_editor_entry_alignment, - "hildon_range_editor_separator_padding", - &range_editor_separator_padding, NULL); - - /* Add padding to separator */ - gtk_misc_set_padding (GTK_MISC (priv->label), - range_editor_separator_padding, 0); - - /* Align the text to right in entry box */ - gtk_entry_set_alignment (GTK_ENTRY (priv->start_entry), - range_editor_entry_alignment); - gtk_entry_set_alignment (GTK_ENTRY (priv->end_entry), - range_editor_entry_alignment); - - gtk_widget_set_composite_name (priv->start_entry, "start_entry"); - gtk_widget_set_composite_name (priv->end_entry, "end_entry"); - gtk_widget_set_composite_name (priv->label, "separator_label"); - gtk_widget_set_parent (priv->start_entry, GTK_WIDGET (editor)); - gtk_widget_set_parent (priv->end_entry, GTK_WIDGET (editor)); - gtk_widget_set_parent (priv->label, GTK_WIDGET (editor)); - - g_signal_connect (G_OBJECT (priv->start_entry), "button-release-event", - G_CALLBACK (hildon_range_editor_released), editor); - g_signal_connect (G_OBJECT (priv->end_entry), "button-release-event", - G_CALLBACK (hildon_range_editor_released), editor); - - g_signal_connect (G_OBJECT (priv->start_entry), "button-press-event", - G_CALLBACK (hildon_range_editor_press), editor); - g_signal_connect (G_OBJECT (priv->end_entry), "button-press-event", - G_CALLBACK (hildon_range_editor_press), editor); - - g_signal_connect (G_OBJECT (priv->start_entry), "key-press-event", - G_CALLBACK (hildon_range_editor_entry_keypress), editor); - g_signal_connect (G_OBJECT (priv->end_entry), "key-press-event", - G_CALLBACK (hildon_range_editor_entry_keypress), editor); - - g_signal_connect (G_OBJECT (priv->start_entry), "focus-in-event", - G_CALLBACK (hildon_range_editor_entry_focus_in), editor); - g_signal_connect (G_OBJECT (priv->end_entry), "focus-in-event", - G_CALLBACK (hildon_range_editor_entry_focus_in), editor); - - g_signal_connect (G_OBJECT (priv->start_entry), "focus-out-event", - G_CALLBACK (hildon_range_editor_entry_focus_out), editor); - g_signal_connect (G_OBJECT (priv->end_entry), "focus-out-event", - G_CALLBACK (hildon_range_editor_entry_focus_out), editor); - g_signal_connect (priv->start_entry, "changed", - G_CALLBACK (hildon_range_editor_entry_changed), editor); - g_signal_connect (priv->end_entry, "changed", - G_CALLBACK (hildon_range_editor_entry_changed), editor); - -#ifdef MAEMO_GTK - g_object_set (G_OBJECT (priv->start_entry), - "hildon-input-mode", HILDON_GTK_INPUT_MODE_NUMERIC, NULL); - - g_object_set( G_OBJECT (priv->end_entry), - "hildon-input-mode", HILDON_GTK_INPUT_MODE_NUMERIC, NULL); -#endif - - gtk_widget_show (priv->start_entry); - gtk_widget_show (priv->end_entry); - gtk_widget_show (priv->label); - - gtk_widget_pop_composite_child(); -} - -static void -hildon_range_editor_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonRangeEditor *editor = HILDON_RANGE_EDITOR(object); - - switch (param_id) - { - case PROP_LOWER: - hildon_range_editor_set_lower (editor, g_value_get_int (value)); - break; - - case PROP_HIGHER: - hildon_range_editor_set_higher (editor, g_value_get_int (value)); - break; - - case PROP_MIN: - hildon_range_editor_set_min (editor, g_value_get_int (value)); - break; - - case PROP_MAX: - hildon_range_editor_set_max (editor, g_value_get_int (value)); - break; - - case PROP_SEPARATOR: - hildon_range_editor_set_separator (editor, - g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); - break; - } -} - -static void -hildon_range_editor_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - HildonRangeEditor *editor = HILDON_RANGE_EDITOR(object); - - switch (param_id) - { - case PROP_LOWER: - g_value_set_int (value, hildon_range_editor_get_lower (editor)); - break; - - case PROP_HIGHER: - g_value_set_int (value, hildon_range_editor_get_higher (editor)); - break; - - case PROP_MIN: - g_value_set_int (value, hildon_range_editor_get_min (editor)); - break; - - case PROP_MAX: - g_value_set_int (value, hildon_range_editor_get_max (editor)); - break; - - case PROP_SEPARATOR: - g_value_set_string (value, hildon_range_editor_get_separator (editor)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); - break; - } -} - -static void -hildon_range_editor_entry_validate (HildonRangeEditor *editor, - GtkWidget *edited_entry, - gboolean allow_intermediate) -{ - HildonRangeEditorPrivate *priv; - const gchar *text; - long value; - gint min, max, fixup; - gchar *tail; - gchar buffer[256]; - gboolean error = FALSE; - - g_assert(HILDON_IS_RANGE_EDITOR(editor)); - g_assert(GTK_IS_ENTRY(edited_entry)); - - priv = HILDON_RANGE_EDITOR_GET_PRIVATE(editor); - g_assert (priv); - - /* Find the valid range for the modified component */ - if (edited_entry == priv->start_entry) { - min = hildon_range_editor_get_min (editor); - max = hildon_range_editor_get_higher (editor); - } else { - min = hildon_range_editor_get_lower (editor); - max = hildon_range_editor_get_max (editor); - } - - text = gtk_entry_get_text (GTK_ENTRY (edited_entry)); - - if (text && text [0]) - { - /* Try to convert entry text to number */ - value = strtol(text, &tail, 10); - - /* Check if conversion succeeded */ - if (tail [0] == 0) - { - /* Check if value is in allowed range. This is tricky in those - cases when user is editing a value. - For example: Range = [100, 500] and user have just inputted "4". - This should not lead into error message. Otherwise value is - resetted back to "100" and next "4" press will reset it back - and so on. */ - if (allow_intermediate) - { - /* We now have the following error cases: - * If inputted value as above maximum and - maximum is either positive or then maximum - negative and value is positive. - * If inputted value is below minimum and minimum - is negative or minumum positive and value - negative. - In all other cases situation can be fixed just by - adding new numbers to the string. - */ - if (value > max && (max >= 0 || (max < 0 && value >= 0))) - { - error = TRUE; - fixup = max; - g_snprintf (buffer, sizeof (buffer), _("ckct_ib_maximum_value"), max); - } - else if (value < min && (min < 0 || (min >= 0 && value < 0))) - { - error = TRUE; - fixup = min; - g_snprintf (buffer, sizeof (buffer), _("ckct_ib_minimum_value"), min); - } - } - else - { - if (value > max) { - error = TRUE; - fixup = max; - g_snprintf (buffer, sizeof (buffer), _("ckct_ib_maximum_value"), max); - } - else if (value < min) { - error = TRUE; - fixup = min; - g_snprintf (buffer, sizeof (buffer), _("ckct_ib_minimum_value"), min); - } - } - - if (error) { - if (edited_entry == priv->start_entry) - hildon_range_editor_set_lower (editor, fixup); - else - hildon_range_editor_set_higher (editor, fixup); - } - } - /* The only valid case when conversion can fail is when we - have plain '-', intermediate forms are allowed AND - minimum bound is negative */ - else if (!allow_intermediate || strcmp(text, "-") != 0 || min >= 0) { - error = TRUE; - g_snprintf (buffer, sizeof (buffer), _("ckct_ib_set_a_value_within_range"), min, max); - } - } - else if (! allow_intermediate) { - error = TRUE; - g_snprintf (buffer, sizeof (buffer), _("ckct_ib_set_a_value_within_range"), min, max); - } - - if (error) - { - hildon_banner_show_information (edited_entry, NULL, buffer); - gtk_widget_grab_focus (edited_entry); - } -} - -static gboolean -hildon_range_editor_entry_focus_in (GtkEditable *editable, - GdkEventFocus *event, - HildonRangeEditor *editor) -{ - HildonRangeEditorPrivate *priv = HILDON_RANGE_EDITOR_GET_PRIVATE(editor); - g_assert (priv); - - if (priv->bp) - { - priv->bp = FALSE; - return FALSE; - } - - if (GTK_WIDGET (editable) == priv->start_entry) - gtk_editable_select_region (editable, -1, 0); - else - gtk_editable_select_region (editable, 0, -1); - return FALSE; -} - -/* Gets and sets the current range. This has two useful side effects: - * Values are now sorted to the correct order - * Out of range values are clamped to range */ -static void -hildon_range_editor_apply_current_range (HildonRangeEditor *editor) -{ - g_assert (HILDON_IS_RANGE_EDITOR (editor)); - - hildon_range_editor_set_range (editor, - hildon_range_editor_get_lower (editor), - hildon_range_editor_get_higher (editor)); -} - -static void -hildon_range_editor_entry_changed (GtkWidget *widget, - HildonRangeEditor *editor) -{ - g_assert (HILDON_IS_RANGE_EDITOR (editor)); - - hildon_range_editor_entry_validate (editor, widget, TRUE); -} - -static gboolean -hildon_range_editor_entry_focus_out (GtkEditable *editable, - GdkEventFocus *event, - HildonRangeEditor *editor) -{ - g_assert (HILDON_IS_RANGE_EDITOR(editor)); - - hildon_range_editor_entry_validate (editor, GTK_WIDGET (editable), FALSE); - return FALSE; -} - -static gboolean -hildon_range_editor_press (GtkEditable *editable, - GdkEventButton *event, - HildonRangeEditor *editor) -{ - HildonRangeEditorPrivate *priv = HILDON_RANGE_EDITOR_GET_PRIVATE(editor); - g_assert (priv); - - priv->bp = TRUE; - return FALSE; -} - -static void -hildon_range_editor_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - HildonRangeEditorPrivate *priv; - - g_assert (HILDON_IS_RANGE_EDITOR (container)); - g_assert (callback != NULL); - - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (container); - g_assert (priv); - - if (! include_internals) - return; - - (*callback) (priv->start_entry, callback_data); - (*callback) (priv->end_entry, callback_data); - (*callback) (priv->label, callback_data); -} - -static void -hildon_range_editor_destroy (GtkObject *self) -{ - HildonRangeEditorPrivate *priv = HILDON_RANGE_EDITOR_GET_PRIVATE (self); - - if (priv->start_entry) - { - gtk_widget_unparent (priv->start_entry); - priv->start_entry = NULL; - } - if (priv->end_entry) - { - gtk_widget_unparent (priv->end_entry); - priv->end_entry = NULL; - } - if (priv->label) - { - gtk_widget_unparent (priv->label); - priv->label = NULL; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - GTK_OBJECT_CLASS (parent_class)->destroy (self); -} - - -static void -hildon_range_editor_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - HildonRangeEditorPrivate *priv = NULL; - GtkRequisition lab_req, mreq; - - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (widget); - g_assert (priv); - - gtk_entry_get_width_chars (GTK_ENTRY (priv->end_entry)); - - gtk_widget_size_request (priv->start_entry, &mreq); - gtk_widget_size_request (priv->end_entry, &mreq); - gtk_widget_size_request (priv->label, &lab_req); - - /* Width for entries and separator label and border */ - requisition->width = mreq.width * 2 + lab_req.width + - widget->style->xthickness * 2; - /* Add vertical border */ - requisition->height = mreq.height + widget->style->ythickness * 2; - /* Fit label height */ - requisition->height = MAX (requisition->height, lab_req.height); -} - -static void -hildon_range_editor_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - HildonRangeEditorPrivate *priv; - GtkAllocation child1_allocation = {0}; - GtkAllocation child2_allocation = {0}; - GtkAllocation child3_allocation = {0}; - - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (widget); - g_assert (priv); - - widget->allocation = *allocation; - - /* Allocate entries, left-to-right */ - if (priv->start_entry && GTK_WIDGET_VISIBLE (priv->start_entry)) - { - GtkRequisition child_requisition; - - gtk_widget_get_child_requisition (priv->start_entry, - &child_requisition); - - child1_allocation.x = allocation->x; - child1_allocation.y = allocation->y; - - child1_allocation.width = child_requisition.width; - child1_allocation.height = allocation->height; - - gtk_widget_size_allocate (priv->start_entry, &child1_allocation); - } - - if (priv->label && GTK_WIDGET_VISIBLE (priv->label)) - { - GtkRequisition child_requisition; - - gtk_widget_get_child_requisition (priv->label, &child_requisition); - - child2_allocation.x = child1_allocation.x + child1_allocation.width; - child2_allocation.y = allocation->y; - /* Add spacing */ - child2_allocation.width = child_requisition.width + 4; - child2_allocation.height = allocation->height; - - gtk_widget_size_allocate (priv->label, &child2_allocation); - } - - if (priv->end_entry && GTK_WIDGET_VISIBLE (priv->end_entry)) - { - GtkRequisition child_requisition; - - gtk_widget_get_child_requisition (priv->end_entry, &child_requisition); - - child3_allocation.x = child2_allocation.x + child2_allocation.width; - child3_allocation.y = allocation->y; - - child3_allocation.width = child_requisition.width; - child3_allocation.height = allocation->height; - - gtk_widget_size_allocate (priv->end_entry, &child3_allocation); - } -} - -/* Button released inside entries */ -static gboolean -hildon_range_editor_released (GtkEditable *editable, - GdkEventButton *event, - HildonRangeEditor *editor) -{ - HildonRangeEditorPrivate *priv = HILDON_RANGE_EDITOR_GET_PRIVATE(editor); - g_assert (priv); - - if (GTK_WIDGET (editable) == priv->start_entry) - gtk_editable_select_region(editable, -1, 0); - else - gtk_editable_select_region(editable, 0, -1); - - return FALSE; -} - -static gboolean -hildon_range_editor_entry_keypress (GtkWidget *widget, - GdkEventKey *event, - HildonRangeEditor *editor) -{ - const gchar *text; - gint cursor_pos; - - g_assert(HILDON_IS_RANGE_EDITOR (editor)); - - text = gtk_entry_get_text (GTK_ENTRY (widget)); - cursor_pos = gtk_editable_get_position (GTK_EDITABLE (widget)); - - switch (event->keyval) - { - case GDK_Left: - /* If we are on the first character and press left, - try to move to previous field */ - if (cursor_pos == 0) { - (void) gtk_widget_child_focus (GTK_WIDGET (editor), GTK_DIR_LEFT); - return TRUE; - } - break; - - case GDK_Right: - /* If the cursor is on the right, try to move to the next field */ - if (cursor_pos >= g_utf8_strlen (text, -1)) { - (void) gtk_widget_child_focus (GTK_WIDGET (editor), GTK_DIR_RIGHT); - return TRUE; - } - break; - - default: - break; - }; - - return FALSE; -} - -static void -hildon_range_editor_refresh_widths (HildonRangeEditorPrivate *priv) -{ - gchar start_range[32], end_range[32]; - gint length; - - /* Calculate length of entry so extremes would fit */ - g_snprintf (start_range, sizeof (start_range), "%d", priv->range_limits_start); - g_snprintf (end_range, sizeof (end_range), "%d", priv->range_limits_end); - length = MAX (g_utf8_strlen (start_range, -1), g_utf8_strlen (end_range, -1)); - - gtk_entry_set_width_chars (GTK_ENTRY (priv->start_entry), length); - gtk_entry_set_max_length (GTK_ENTRY (priv->start_entry), length); - gtk_entry_set_width_chars (GTK_ENTRY (priv->end_entry), length); - gtk_entry_set_max_length (GTK_ENTRY (priv->end_entry), length); -} - -/** - * hildon_range_editor_get_type: - * - * Initializes, and returns the type of a hildon range editor. - * - * Returns: GType of #HildonRangeEditor - * - */ -GType G_GNUC_CONST -hildon_range_editor_get_type (void) -{ - static GType editor_type = 0; - - if (! editor_type) - { - static const GTypeInfo editor_info = - { - sizeof (HildonRangeEditorClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_range_editor_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonRangeEditor), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_range_editor_init, - }; - editor_type = g_type_register_static (GTK_TYPE_CONTAINER, - "HildonRangeEditor", - &editor_info, 0); - } - return editor_type; -} - -/** - * hildon_range_editor_new: - * - * HildonRangeEditor contains two GtkEntrys that accept numbers and minus. - * - * Returns: pointer to a new @HildonRangeEditor widget - */ -GtkWidget* -hildon_range_editor_new (void) -{ - return GTK_WIDGET (g_object_new (HILDON_TYPE_RANGE_EDITOR, NULL)); -} - -/** - * hildon_range_editor_new_with_separator: - * @separator: a string that is shown between the numbers - * - * HildonRangeEditor contains two Gtk entries that accept numbers. - * A separator is displayed between two entries. - * CHECKME: Use '-' as a separator in the case of null separator? - * - * Returns: pointer to a new @HildonRangeEditor widget - */ -GtkWidget* -hildon_range_editor_new_with_separator (const gchar *separator) -{ - return GTK_WIDGET (g_object_new (HILDON_TYPE_RANGE_EDITOR, - "separator", separator, NULL)); -} - -/** - * hildon_range_editor_set_range: - * @editor: the #HildonRangeEditor widget - * @start: range's start value - * @end: range's end value - * - * Sets a range to the editor. (The current value) - * - * Sets the range of the @HildonRangeEditor widget. - */ -void -hildon_range_editor_set_range (HildonRangeEditor *editor, - gint start, - gint end) -{ - g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor)); - - /* Make sure that the start/end appear in the correct order */ - hildon_range_editor_set_lower (editor, MIN (start, end)); - hildon_range_editor_set_higher (editor, MAX (start, end)); -} - -/** - * hildon_range_editor_get_range: - * @editor: the #HildonRangeEditor widget - * @start: ranges start value - * @end: ranges end value - * - * Gets the range of the @HildonRangeEditor widget. - */ -void -hildon_range_editor_get_range (HildonRangeEditor *editor, - gint *start, - gint *end) -{ - g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor) && start && end); - - *start = hildon_range_editor_get_lower (editor); - *end = hildon_range_editor_get_higher (editor); -} - -/** - * hildon_range_editor_set_limits: - * @editor: the #HildonRangeEditor widget - * @start: minimum acceptable value (default: no limit) - * @end: maximum acceptable value (default: no limit) - * - * Sets the range of the @HildonRangeEditor widget. - */ -void -hildon_range_editor_set_limits (HildonRangeEditor *editor, - gint start, - gint end) -{ - /* FIXME: Setting start/end as separate steps can modify - the inputted range unneedlesly */ - hildon_range_editor_set_min (editor, start); - hildon_range_editor_set_max (editor, end); -} - -void -hildon_range_editor_set_lower (HildonRangeEditor *editor, - gint value) -{ - HildonRangeEditorPrivate *priv; - gchar buffer[32]; - - g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor)); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - - g_snprintf(buffer, sizeof (buffer), "%d", - CLAMP (value, priv->range_limits_start, priv->range_limits_end)); - - /* Update entry text with new value */ - gtk_entry_set_text (GTK_ENTRY (priv->start_entry), buffer); - g_object_notify (G_OBJECT (editor), "lower"); -} - -void -hildon_range_editor_set_higher (HildonRangeEditor *editor, - gint value) -{ - HildonRangeEditorPrivate *priv; - gchar buffer[32]; - - g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor)); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - - g_snprintf(buffer, sizeof(buffer), "%d", - CLAMP(value, priv->range_limits_start, priv->range_limits_end)); - - /* Update entry text with new value */ - gtk_entry_set_text (GTK_ENTRY (priv->end_entry), buffer); - g_object_notify (G_OBJECT (editor), "higher"); -} - -gint -hildon_range_editor_get_lower (HildonRangeEditor *editor) -{ - HildonRangeEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), 0); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - return atoi(gtk_entry_get_text(GTK_ENTRY(priv->start_entry))); -} - -gint -hildon_range_editor_get_higher (HildonRangeEditor *editor) -{ - HildonRangeEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), 0); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - return atoi (gtk_entry_get_text(GTK_ENTRY (priv->end_entry))); -} - -void -hildon_range_editor_set_min (HildonRangeEditor *editor, - gint value) -{ - HildonRangeEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor)); - - /* We can cause many properties to change */ - g_object_freeze_notify (G_OBJECT(editor)); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - priv->range_limits_start = value; - - if (priv->range_limits_end < value) - hildon_range_editor_set_max (editor, value); - /* Setting maximum applies widths and range in this case */ - else { - hildon_range_editor_refresh_widths (priv); - hildon_range_editor_apply_current_range (editor); - } - - g_object_notify (G_OBJECT (editor), "min"); - g_object_thaw_notify (G_OBJECT (editor)); -} - -void -hildon_range_editor_set_max (HildonRangeEditor *editor, - gint value) -{ - HildonRangeEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor)); - - /* We can cause many properties to change */ - g_object_freeze_notify (G_OBJECT (editor)); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - priv->range_limits_end = value; - - if (priv->range_limits_start > value) - hildon_range_editor_set_min (editor, value); - /* Setting minimum applies widths and range in this case */ - else { - hildon_range_editor_refresh_widths (priv); - hildon_range_editor_apply_current_range (editor); - } - - g_object_notify (G_OBJECT (editor), "max"); - g_object_thaw_notify (G_OBJECT (editor)); -} - -gint -hildon_range_editor_get_min (HildonRangeEditor *editor) -{ - HildonRangeEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), 0); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - - return priv->range_limits_start; -} - -gint -hildon_range_editor_get_max (HildonRangeEditor *editor) -{ - HildonRangeEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), 0); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - - return priv->range_limits_end; -} - -void -hildon_range_editor_set_separator (HildonRangeEditor *editor, - const gchar *separator) -{ - HildonRangeEditorPrivate *priv; - g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor)); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - - gtk_label_set_text (GTK_LABEL (priv->label), separator); - g_object_notify (G_OBJECT(editor), "separator"); -} - -const gchar* -hildon_range_editor_get_separator (HildonRangeEditor *editor) -{ - HildonRangeEditorPrivate *priv; - g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), NULL); - priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor); - - return gtk_label_get_text (GTK_LABEL (priv->label)); -} diff --git a/hildon/hildon-range-editor.h b/hildon/hildon-range-editor.h deleted file mode 100644 index 3438b4b..0000000 --- a/hildon/hildon-range-editor.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_RANGE_EDITOR_H__ -#define __HILDON_RANGE_EDITOR_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_RANGE_EDITOR \ - (hildon_range_editor_get_type()) - -#define HILDON_RANGE_EDITOR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_RANGE_EDITOR, HildonRangeEditor)) - -#define HILDON_RANGE_EDITOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_RANGE_EDITOR, HildonRangeEditorClass)) - -#define HILDON_IS_RANGE_EDITOR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_RANGE_EDITOR)) - -#define HILDON_IS_RANGE_EDITOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_RANGE_EDITOR)) - -#define HILDON_RANGE_EDITOR_GET_CLASS(obj) \ - ((HildonRangeEditorClass *) G_OBJECT_GET_CLASS(obj)) - -typedef struct _HildonRangeEditor HildonRangeEditor; - -typedef struct _HildonRangeEditorClass HildonRangeEditorClass; - -struct _HildonRangeEditor -{ - GtkContainer parent; -}; - -struct _HildonRangeEditorClass -{ - GtkContainerClass parent_class; -}; - -GType G_GNUC_CONST -hildon_range_editor_get_type (void); - -GtkWidget* -hildon_range_editor_new_with_separator (const gchar * separator); - -GtkWidget* -hildon_range_editor_new (void); - -void -hildon_range_editor_set_range (HildonRangeEditor *editor, - gint start, - gint end); - -void -hildon_range_editor_get_range (HildonRangeEditor *editor, - gint * start, - gint * end); - -void -hildon_range_editor_set_limits (HildonRangeEditor *editor, - gint start, - gint end); - -void -hildon_range_editor_set_lower (HildonRangeEditor *editor, - gint value); - -void -hildon_range_editor_set_higher (HildonRangeEditor *editor, - gint value); - -gint -hildon_range_editor_get_lower (HildonRangeEditor *editor); - -gint -hildon_range_editor_get_higher (HildonRangeEditor *editor); - -void -hildon_range_editor_set_min (HildonRangeEditor *editor, - gint value); - -void -hildon_range_editor_set_max (HildonRangeEditor *editor, - gint value); - -gint -hildon_range_editor_get_min (HildonRangeEditor *editor); - -gint -hildon_range_editor_get_max (HildonRangeEditor *editor); - -void -hildon_range_editor_set_separator (HildonRangeEditor *editor, - const gchar *separator); - -const gchar* -hildon_range_editor_get_separator (HildonRangeEditor *editor); - -G_END_DECLS - -#endif /* __HILDON_RANGE_EDITOR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ - diff --git a/hildon/hildon-seekbar-private.h b/hildon/hildon-seekbar-private.h deleted file mode 100644 index b58f881..0000000 --- a/hildon/hildon-seekbar-private.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_SEEKBAR_PRIVATE_H__ -#define __HILDON_SEEKBAR_PRIVATE_H__ - -G_BEGIN_DECLS - -typedef struct _HildonSeekbarPrivate HildonSeekbarPrivate; - -#define HILDON_SEEKBAR_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_SEEKBAR, HildonSeekbarPrivate)); - -struct _HildonSeekbarPrivate -{ - gboolean is_toolbar; /* TRUE if this widget is inside a toolbar */ - guint fraction; /* This is the amount of time that has progressed from - the beginning. It should be an integer between the - minimum and maximum values of the corresponding - adjustment, ie. adjument->lower and ->upper.. */ -}; - -G_END_DECLS - -#endif /* __HILDON_SEEKBAR_PRIVATE_H__ */ diff --git a/hildon/hildon-seekbar.c b/hildon/hildon-seekbar.c deleted file mode 100644 index cc77140..0000000 --- a/hildon/hildon-seekbar.c +++ /dev/null @@ -1,623 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-seekbar - * @short_description: A widget used to identify a place from a content. - * - * HildonSeekbar allows seeking in media with a range widget. It - * supports for setting or getting the length (total time) of the media, - * the position within it and the fraction (maximum position in a - * stream/the amount currently downloaded). The position is clamped - * between zero and the total time, or zero and the fraction in case of - * a stream. - * - * #HildonSeekbar has been deprecated since hildon 2.2. Use #GtkScale - * instead. See hildon_gtk_hscale_new() and hildon_gtk_vscale_new(). - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <libintl.h> -#include <stdio.h> -#include <math.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-seekbar.h" -#include "hildon-seekbar-private.h" - -static GtkScaleClass* parent_class = NULL; - -static void -hildon_seekbar_class_init (HildonSeekbarClass *seekbar_class); - -static void -hildon_seekbar_init (HildonSeekbar *seekbar); - -static void -hildon_seekbar_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_seekbar_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static void -hildon_seekbar_size_request (GtkWidget *widget, - GtkRequisition *event); - -static void -hildon_seekbar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static gboolean -hildon_seekbar_button_press_event (GtkWidget *widget, - GdkEventButton *event); - -static gboolean -hildon_seekbar_button_release_event (GtkWidget *widget, - GdkEventButton *event); - -static gboolean -hildon_seekbar_keypress (GtkWidget *widget, - GdkEventKey *event); - -#define MINIMUM_WIDTH 115 - -#define DEFAULT_HEIGHT 58 - -#define TOOL_MINIMUM_WIDTH 75 - -#define TOOL_DEFAULT_HEIGHT 40 - -#define DEFAULT_DISPLAYC_BORDER 10 - -#define BUFFER_SIZE 32 - -#define EXTRA_SIDE_BORDER 20 - -#define TOOL_EXTRA_SIDE_BORDER 0 - -#define NUM_STEPS 20 - -#define SECONDS_PER_MINUTE 60 - -/* the number of digits precision for the internal range. - * note, this needs to be enough so that the step size for - * small total_times doesn't get rounded off. Currently set to 3 - * this is because for the smallest total time ( i.e 1 ) and the current - * num steps ( 20 ) is: 1/20 = 0.05. 0.05 is 2 digits, and we - * add one for safety */ -#define MAX_ROUND_DIGITS 3 - -enum -{ - PROP_0, - PROP_TOTAL_TIME, - PROP_POSITION, - PROP_FRACTION -}; - -/** - * hildon_seekbar_get_type: - * - * Initializes, and returns the type of a hildon seekbar. - * - * Returns: GType of #HildonSeekbar - * - */ -GType G_GNUC_CONST -hildon_seekbar_get_type (void) -{ - static GType seekbar_type = 0; - - if (!seekbar_type) { - static const GTypeInfo seekbar_info = { - sizeof (HildonSeekbarClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_seekbar_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonSeekbar), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_seekbar_init, - }; - seekbar_type = g_type_register_static(GTK_TYPE_SCALE, - "HildonSeekbar", - &seekbar_info, 0); - } - - return seekbar_type; -} - -/** - * Initialises the seekbar class. - */ -static void -hildon_seekbar_class_init (HildonSeekbarClass *seekbar_class) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (seekbar_class); - GObjectClass *object_class = G_OBJECT_CLASS (seekbar_class); - - parent_class = g_type_class_peek_parent (seekbar_class); - - g_type_class_add_private (seekbar_class, sizeof (HildonSeekbarPrivate)); - - widget_class->size_request = hildon_seekbar_size_request; - widget_class->size_allocate = hildon_seekbar_size_allocate; - widget_class->button_press_event = hildon_seekbar_button_press_event; - widget_class->button_release_event = hildon_seekbar_button_release_event; - widget_class->key_press_event = hildon_seekbar_keypress; - - object_class->set_property = hildon_seekbar_set_property; - object_class->get_property = hildon_seekbar_get_property; - - /** - * HildonSeekbar:total-time: - * - * Total playing time of this media file. - */ - g_object_class_install_property (object_class, PROP_TOTAL_TIME, - g_param_spec_double ("total-time", - "total time", - "Total playing time of this media file", - 0, /* min value */ - G_MAXDOUBLE, /* max value */ - 0, /* default */ - G_PARAM_READWRITE)); - - /** - * HildonSeekbar:position: - * - * Current position in this media file. - */ - g_object_class_install_property (object_class, PROP_POSITION, - g_param_spec_double ("position", - "position", - "Current position in this media file", - 0, /* min value */ - G_MAXDOUBLE, /* max value */ - 0, /* default */ - G_PARAM_READWRITE)); - - /** - * HildonSeekbar:fraction: - * - * Current fraction related to the progress indicator. - */ - g_object_class_install_property (object_class, PROP_FRACTION, - g_param_spec_double ("fraction", - "Fraction", - "current fraction related to the" - "progress indicator", - 0, /* min value */ - G_MAXDOUBLE, /* max value */ - 0, /* default */ - G_PARAM_READWRITE)); -} - - -static void -hildon_seekbar_init (HildonSeekbar *seekbar) -{ - GtkRange *range = GTK_RANGE(seekbar); - - /* Initialize range widget */ - range->orientation = GTK_ORIENTATION_HORIZONTAL; - range->flippable = TRUE; - range->round_digits = MAX_ROUND_DIGITS; - - gtk_scale_set_draw_value (GTK_SCALE (seekbar), FALSE); -} - -/* - * Purpose of this function is to prevent Up and Down keys from - * changing the widget's value (like Left and Right). Instead they - * are used for changing focus to other widgtes. - */ -static gboolean -hildon_seekbar_keypress (GtkWidget *widget, - GdkEventKey *event) -{ - if (event->keyval == GDK_Up || event->keyval == GDK_Down) - return FALSE; - - return ((GTK_WIDGET_CLASS (parent_class)->key_press_event) (widget, event)); -} - -static void -hildon_seekbar_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonSeekbar *seekbar = HILDON_SEEKBAR (object); - - switch (prop_id) { - - case PROP_TOTAL_TIME: - hildon_seekbar_set_total_time (seekbar, g_value_get_double (value)); - break; - - case PROP_POSITION: - hildon_seekbar_set_position (seekbar, g_value_get_double (value)); - break; - - case PROP_FRACTION: - hildon_seekbar_set_fraction (seekbar, g_value_get_double (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/* handle getting of seekbar properties */ -static void -hildon_seekbar_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GtkRange *range = GTK_RANGE (object); - - switch (prop_id) { - - case PROP_TOTAL_TIME: - g_value_set_double (value, range->adjustment->upper); - break; - - case PROP_POSITION: - g_value_set_double (value, range->adjustment->value); - break; - - case PROP_FRACTION: - g_value_set_double (value, - hildon_seekbar_get_fraction (HILDON_SEEKBAR(object))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/** - * hildon_seekbar_new: - * - * Create a new #HildonSeekbar widget. - * - * Returns: a #GtkWidget pointer of #HildonSeekbar widget - */ -GtkWidget* -hildon_seekbar_new (void) -{ - return g_object_new (HILDON_TYPE_SEEKBAR, NULL); -} - -/** - * hildon_seekbar_get_total_time: - * @seekbar: a #HildonSeekbar - * - * Gets the total playing time of the media (in seconds). - * - * Returns: total playing time. - */ -gint -hildon_seekbar_get_total_time (HildonSeekbar *seekbar) -{ - GtkWidget *widget; - widget = GTK_WIDGET (seekbar); - g_return_val_if_fail (HILDON_IS_SEEKBAR (seekbar), 0); - g_return_val_if_fail (GTK_RANGE (widget)->adjustment, 0); - return GTK_RANGE (widget)->adjustment->upper; -} - -/** - * hildon_seekbar_set_total_time: - * @seekbar: a #HildonSeekbar - * @time: integer greater than zero - * - * Set total playing time of media in seconds. - */ -void -hildon_seekbar_set_total_time (HildonSeekbar *seekbar, - gint time) -{ - GtkAdjustment *adj; - GtkWidget *widget; - gboolean value_changed = FALSE; - - g_return_if_fail (HILDON_IS_SEEKBAR (seekbar)); - widget = GTK_WIDGET (seekbar); - - if (time <= 0) { - return; - } - - g_return_if_fail (GTK_RANGE (widget)->adjustment); - - adj = GTK_RANGE (widget)->adjustment; - adj->upper = time; - - /* Clamp position to total time */ - if (adj->value > time) { - adj->value = time; - value_changed = TRUE; - } - - /* Calculate new step value */ - adj->step_increment = adj->upper / NUM_STEPS; - adj->page_increment = adj->step_increment; - - gtk_adjustment_changed (adj); - - /* Update range widget position/fraction */ - if (value_changed) { - gtk_adjustment_value_changed (adj); - hildon_seekbar_set_fraction(seekbar, - MIN (hildon_seekbar_get_fraction (seekbar), - time)); - - g_object_freeze_notify (G_OBJECT (seekbar)); - - hildon_seekbar_set_position (seekbar, - MIN (hildon_seekbar_get_position (seekbar), - time)); - - g_object_notify(G_OBJECT (seekbar), "total-time"); - - g_object_thaw_notify (G_OBJECT (seekbar)); - } -} - -/** - * hildon_seekbar_get_fraction: - * @seekbar: pointer to #HildonSeekbar widget - * - * Get current fraction value of the rage. - * - * Returns: current fraction - */ -guint -hildon_seekbar_get_fraction (HildonSeekbar *seekbar) -{ - g_return_val_if_fail (HILDON_IS_SEEKBAR (seekbar), 0); - -#if defined(MAEMO_GTK) || GTK_CHECK_VERSION(2,11,0) - return gtk_range_get_fill_level (GTK_RANGE (seekbar)); -#else - return 0; -#endif -} - -/** - * hildon_seekbar_set_fraction: - * @seekbar: pointer to #HildonSeekbar widget - * @fraction: the new position of the progress indicator - * - * Set current fraction value of the range. - * It should be between the minimal and maximal values of the range in seekbar. - */ -void -hildon_seekbar_set_fraction (HildonSeekbar *seekbar, - guint fraction) -{ - GtkRange *range = NULL; - g_return_if_fail (HILDON_IS_SEEKBAR (seekbar)); - - range = GTK_RANGE(GTK_WIDGET(seekbar)); - - g_return_if_fail (fraction <= range->adjustment->upper && - fraction >= range->adjustment->lower); - - /* Set to show stream indicator. */ - g_object_set (G_OBJECT (seekbar), "show-fill-level", TRUE, NULL); - - fraction = CLAMP (fraction, range->adjustment->lower, - range->adjustment->upper); - -#if defined(MAEMO_GTK) || GTK_CHECK_VERSION(2,11,0) - /* Update stream position of range widget */ - gtk_range_set_fill_level (range, fraction); -#endif - - if (fraction < hildon_seekbar_get_position(seekbar)) - hildon_seekbar_set_position(seekbar, fraction); - - g_object_notify (G_OBJECT (seekbar), "fraction"); -} - -/** - * hildon_seekbar_get_position: - * @seekbar: pointer to #HildonSeekbar widget - * - * Get current position in stream in seconds. - * - * Returns: current position in stream in seconds - */ -gint -hildon_seekbar_get_position (HildonSeekbar *seekbar) -{ - g_return_val_if_fail (HILDON_IS_SEEKBAR(seekbar), 0); - g_return_val_if_fail (GTK_RANGE(seekbar)->adjustment, 0); - - return GTK_RANGE (seekbar)->adjustment->value; -} - -/** - * hildon_seekbar_set_position: - * @seekbar: pointer to #HildonSeekbar widget - * @time: time within range of >= 0 && < G_MAXINT - * - * Set current position in stream in seconds. - */ -void -hildon_seekbar_set_position (HildonSeekbar *seekbar, - gint time) -{ - GtkRange *range; - GtkAdjustment *adj; - gint value; - - g_return_if_fail (time >= 0); - g_return_if_fail (HILDON_IS_SEEKBAR(seekbar)); - range = GTK_RANGE (seekbar); - adj = range->adjustment; - g_return_if_fail (adj); - - /* only change value if it is a different int. this allows us to have - smooth scrolls for small total_times */ - value = floor (adj->value); - if (time != value) { - value = (time < adj->upper) ? time : adj->upper; - -#if defined(MAEMO_GTK) || GTK_CHECK_VERSION(2,11,0) - if (value <= gtk_range_get_fill_level (range)) { -#else - if (value) { -#endif - adj->value = value; - gtk_adjustment_value_changed (adj); - - g_object_notify (G_OBJECT (seekbar), "position"); - } - } -} - -static void -hildon_seekbar_size_request (GtkWidget *widget, - GtkRequisition *req) -{ - HildonSeekbar *self = NULL; - HildonSeekbarPrivate *priv = NULL; - GtkWidget *parent = NULL; - - self = HILDON_SEEKBAR (widget); - priv = HILDON_SEEKBAR_GET_PRIVATE (self); - - parent = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_TOOLBAR); - - priv->is_toolbar = parent ? TRUE : FALSE; - - if (GTK_WIDGET_CLASS (parent_class)->size_request) - GTK_WIDGET_CLASS (parent_class)->size_request (widget, req); - - /* Request minimum size, depending on whether the widget is in a - * toolbar or not */ - req->width = priv->is_toolbar ? TOOL_MINIMUM_WIDTH : MINIMUM_WIDTH; - req->height = priv->is_toolbar ? TOOL_DEFAULT_HEIGHT : DEFAULT_HEIGHT; -} - -static void -hildon_seekbar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - HildonSeekbarPrivate *priv; - - priv = HILDON_SEEKBAR_GET_PRIVATE (widget); - - if (priv->is_toolbar == TRUE) - { - /* Center vertically */ - if (allocation->height > TOOL_DEFAULT_HEIGHT) - { - allocation->y += - (allocation->height - TOOL_DEFAULT_HEIGHT) / 2; - allocation->height = TOOL_DEFAULT_HEIGHT; - } - /* Add space for border */ - allocation->x += TOOL_EXTRA_SIDE_BORDER; - allocation->width -= 2 * TOOL_EXTRA_SIDE_BORDER; - } - else - { - /* Center vertically */ - if (allocation->height > DEFAULT_HEIGHT) - { - allocation->y += (allocation->height - DEFAULT_HEIGHT) / 2; - allocation->height = DEFAULT_HEIGHT; - } - - /* Add space for border */ - allocation->x += EXTRA_SIDE_BORDER; - allocation->width -= 2 * EXTRA_SIDE_BORDER; - } - - if (GTK_WIDGET_CLASS (parent_class)->size_allocate) - GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); -} - -/* - * Event handler for button press. Changes button1 to button2. - */ -static gboolean -hildon_seekbar_button_press_event (GtkWidget *widget, - GdkEventButton *event) -{ - gint result = FALSE; - - /* We change here the button id because we want to use button2 - * functionality for button1: jump to mouse position - * instead of slowly incrementing to it */ - if (event->button == 1) event->button = 2; - - /* call the parent handler */ - if (GTK_WIDGET_CLASS (parent_class)->button_press_event) - result = GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, - event); - - return result; -} -/* - * Event handler for button release. Changes button1 to button2. - */ -static gboolean -hildon_seekbar_button_release_event (GtkWidget *widget, - GdkEventButton *event) -{ - gboolean result = FALSE; - - /* We change here the button id because we want to use button2 - * functionality for button1: jump to mouse position - * instead of slowly incrementing to it */ - event->button = event->button == 1 ? 2 : event->button; - - /* call the parent handler */ - if (GTK_WIDGET_CLASS (parent_class)->button_release_event) - result = GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, - event); - - return result; -} diff --git a/hildon/hildon-seekbar.h b/hildon/hildon-seekbar.h deleted file mode 100644 index 25732ad..0000000 --- a/hildon/hildon-seekbar.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_SEEKBAR_H__ -#define __HILDON_SEEKBAR_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_SEEKBAR \ - (hildon_seekbar_get_type()) - -#define HILDON_SEEKBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj,\ - HILDON_TYPE_SEEKBAR, HildonSeekbar)) - -#define HILDON_SEEKBAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_SEEKBAR, HildonSeekbarClass)) - -#define HILDON_IS_SEEKBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_SEEKBAR)) - -#define HILDON_IS_SEEKBAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass),\ - HILDON_TYPE_SEEKBAR)) - -#define HILDON_SEEKBAR_GET_CLASS(obj) \ - ((HildonSeekBarClass *) G_OBJECT_GET_CLASS(obj)) - - -typedef struct _HildonSeekbar HildonSeekbar; - -typedef struct _HildonSeekbarClass HildonSeekbarClass; - -struct _HildonSeekbar -{ - GtkScale parent; -}; - -struct _HildonSeekbarClass -{ - GtkScaleClass parent_class; -}; - -GType G_GNUC_CONST -hildon_seekbar_get_type (void); - -GtkWidget* -hildon_seekbar_new (void); - -gint -hildon_seekbar_get_total_time (HildonSeekbar *seekbar); - -void -hildon_seekbar_set_total_time (HildonSeekbar *seekbar, - gint time); - -gint -hildon_seekbar_get_position (HildonSeekbar *seekbar); - -void -hildon_seekbar_set_position (HildonSeekbar *seekbar, - gint time); - -void -hildon_seekbar_set_fraction (HildonSeekbar *seekbar, - guint fraction); - -guint -hildon_seekbar_get_fraction (HildonSeekbar *seekbar); - -G_END_DECLS - -#endif /* __HILDON_SEEKBAR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-set-password-dialog-private.h b/hildon/hildon-set-password-dialog-private.h deleted file mode 100644 index 1eef7f3..0000000 --- a/hildon/hildon-set-password-dialog-private.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_SET_PASSWORD_DIALOG_PRIVATE_H__ -#define __HILDON_SET_PASSWORD_DIALOG_PRIVATE_H__ - -G_BEGIN_DECLS - -#define HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE(obj)\ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_SET_PASSWORD_DIALOG, \ - HildonSetPasswordDialogPrivate)); - -typedef struct _HildonSetPasswordDialogPrivate HildonSetPasswordDialogPrivate; - -struct _HildonSetPasswordDialogPrivate -{ - GtkWidget *checkbox; - - GtkLabel *message_label; - - GtkWidget *pwd1st_entry; - GtkWidget *pwd1st_caption; - gchar *pwd1st_caption_string; - - GtkWidget *pwd2nd_entry; - GtkWidget *pwd2nd_caption; - gchar *pwd2nd_caption_string; - - gboolean protection; -}; - -G_END_DECLS - -#endif /* __HILDON_SET_PASSWORD_DIALOG_PRIVATE_H__ */ diff --git a/hildon/hildon-set-password-dialog.c b/hildon/hildon-set-password-dialog.c deleted file mode 100644 index 11246e4..0000000 --- a/hildon/hildon-set-password-dialog.c +++ /dev/null @@ -1,744 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006, 2009 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-set-password-dialog - * @short_description: A dialog used to set, change or remove a password. - * @see_also: #HildonGetPasswordDialog - * - * HildonSetPasswordDialog allows setting and changing a password. - * - * In Change mode: Dialog is used to change or remove an existing - * password. Unselecting the check box dims the password fields below - * it. If the dialog is accepted with 'OK' while the check box is - * unselected, a Confirmation Note is shown. If the Confirmation Note - * Dialog is accepted with 'Remove', the password protection is removed. - * - * In Set mode: Set Password Dialog is used to define a password, or - * change a password that cannot be removed. - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <errno.h> -#include <string.h> -#include <strings.h> -#include <unistd.h> -#include <stdio.h> -#include <libintl.h> -#include <glib.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-stock.h" -#include "hildon-set-password-dialog.h" -#include "hildon-caption.h" -#include "hildon-note.h" -#include "hildon-defines.h" -#include "hildon-banner.h" -#include "hildon-set-password-dialog-private.h" -#include "hildon-entry.h" -#include "hildon-check-button.h" - -#define HILDON_SET_PASSWORD_DIALOG_TITLE "ecdg_ti_set_password" - -#define HILDON_SET_PASSWORD_DIALOG_PASSWORD "ecdg_fi_set_passwd_enter_pwd" - -#define HILDON_SET_PASSWORD_DIALOG_VERIFY_PASSWORD "ecdg_fi_set_passwd_confirm" - -#define HILDON_SET_PASSWORD_DIALOG_OK HILDON_STOCK_DONE - -#define HILDON_SET_PASSWORD_DIALOG_CANCEL "ecdg_bd_set_password_dialog_cancel" - -#define HILDON_SET_MODIFY_PASSWORD_DIALOG_TITLE "ckdg_ti_dialog_c_passwd_change_password" - -#define HILDON_SET_MODIFY_PASSWORD_DIALOG_LABEL "ckdg_fi_dialog_c_passwd_pwd_protect" - -#define HILDON_SET_MODIFY_PASSWORD_DIALOG_PASSWORD "ckdg_fi_dialog_c_passwd_new_pwd" - -#define HILDON_SET_MODIFY_PASSWORD_DIALOG_VERIFY_PASSWORD "ckdg_fi_dialog_c_passwd_ver_pwd" - -#define HILDON_SET_MODIFY_PASSWORD_DIALOG_OK HILDON_STOCK_DONE - -#define HILDON_SET_MODIFY_PASSWORD_DIALOG_CANCEL "ckdg_bd_change_password_dialog_cancel" - -#define HILDON_SET_PASSWORD_DIALOG_MISMATCH "ecdg_ib_passwords_do_not_match" - -#define HILDON_SET_PASSWORD_DIALOG_EMPTY "ecdg_ib_password_is_empty" - -#define HILDON_SET_PASSWORD_DIALOG_REMOVE_PROTECTION "ckdg_nc_dialog_c_passwd_remove_pwd" - -#define HILDON_REMOVE_PROTECTION_CONFIRMATION_REMOVE "ckdg_bd_dialog_c_passwd_remove_button" - -#define HILDON_REMOVE_PROTECTION_CONFIRMATION_CANCEL "ckdg_bd_dialog_c_passwd_cancel_button" - -#define _(String) dgettext("hildon-libs", String) - -#define c_(String) dgettext("hildon-common-strings", String) - -static GtkDialogClass* parent_class; - -static void -hildon_set_password_dialog_class_init (HildonSetPasswordDialogClass *class); - -static void -hildon_set_password_dialog_init (HildonSetPasswordDialog *dialog); - -static void -hildon_checkbox_toggled (GtkWidget *widget, - gpointer dialog); - -static void -hildon_set_password_response_change (GtkDialog *d, - gint arg1, - gpointer unused); - -static void -hildon_set_password_response_set (GtkDialog * d, - gint arg1, - gpointer unused); - -static void -create_contents (HildonSetPasswordDialog *dialog); - -static void -hildon_set_password_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_set_password_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -enum -{ - PROP_0, - PROP_MESSAGE, - PROP_PASSWORD, - PROP_HILDON_PASSWORD_DIALOG -}; - -static void -hildon_set_password_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonSetPasswordDialog *dialog = HILDON_SET_PASSWORD_DIALOG (object); - HildonSetPasswordDialogPrivate *priv; - - priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - switch (prop_id) { - - case PROP_MESSAGE: - /* Update domain label to display new value */ - gtk_label_set_text (priv->message_label, g_value_get_string (value)); - break; - - case PROP_PASSWORD: - /* Update password entry to display new value */ - gtk_entry_set_text (GTK_ENTRY (priv->pwd1st_entry), g_value_get_string (value)); - break; - - case PROP_HILDON_PASSWORD_DIALOG: - /* Note this is a G_PARAM_CONSTRUCT_ONLY type property */ - priv->protection = g_value_get_boolean (value); - - /* We now have the necessary information to populate the dialog */ - /* FIXME It looks kinda extremally bad that this is here... - * what about situations where this prop is NOT set during - * constructing? */ - create_contents (dialog); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_set_password_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - HildonSetPasswordDialogPrivate *priv = NULL; - - priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (object); - g_assert (priv); - - switch (prop_id) { - - case PROP_MESSAGE: - g_value_set_string (value, gtk_label_get_text (priv->message_label)); - break; - - case PROP_PASSWORD: - g_value_set_string (value, - gtk_entry_get_text (GTK_ENTRY (priv->pwd1st_entry))); - break; - - case PROP_HILDON_PASSWORD_DIALOG: - g_value_set_boolean (value, priv->protection); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - -static void -create_contents (HildonSetPasswordDialog *dialog) -{ - HildonSetPasswordDialogPrivate *priv = NULL; - AtkObject *atk_aux = NULL; - - GtkSizeGroup *group; - - priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - priv->checkbox = NULL; - - /* Size group for labels */ - group = GTK_SIZE_GROUP (gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL)); - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - - /* Setup and pack domain label */ - priv->message_label = GTK_LABEL (gtk_label_new (NULL)); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - GTK_WIDGET(priv->message_label), FALSE, FALSE, 0); - gtk_widget_show (GTK_WIDGET (priv->message_label)); - - if (priv->protection == TRUE) { - /* Use Change Password Dialog strings */ - priv->pwd1st_caption_string = _(HILDON_SET_MODIFY_PASSWORD_DIALOG_PASSWORD); - priv->pwd2nd_caption_string = _(HILDON_SET_MODIFY_PASSWORD_DIALOG_VERIFY_PASSWORD); - - /* Setup checkbox to enable/disable password protection */ - priv->checkbox = hildon_check_button_new (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT); - gtk_button_set_label (GTK_BUTTON (priv->checkbox), _(HILDON_SET_MODIFY_PASSWORD_DIALOG_LABEL)); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), - priv->checkbox, TRUE, TRUE, 0); - gtk_widget_show (priv->checkbox); - hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox), - TRUE); - gtk_signal_connect (GTK_OBJECT (priv->checkbox), "toggled", - G_CALLBACK (hildon_checkbox_toggled), dialog); - - /* Setup appropriate response handler */ - g_signal_connect (G_OBJECT (dialog), "response", - G_CALLBACK (hildon_set_password_response_change), - NULL); - } else { - /* Use Set Password Dialog strings */ - priv->pwd1st_caption_string = _(HILDON_SET_PASSWORD_DIALOG_PASSWORD); - priv->pwd2nd_caption_string = _(HILDON_SET_PASSWORD_DIALOG_VERIFY_PASSWORD); - - /* Setup appropriate response handler */ - g_signal_connect (G_OBJECT (dialog), "response", - G_CALLBACK(hildon_set_password_response_set), - NULL); - } - - /* Create the password field */ - priv->pwd1st_entry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); - if ((atk_aux = gtk_widget_get_accessible(priv->pwd1st_entry))) - { - atk_object_set_name(atk_aux, "Old Passwd"); - } - - -#ifdef MAEMO_GTK - g_object_set (priv->pwd1st_entry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL); -#endif - - gtk_entry_set_visibility (GTK_ENTRY(priv->pwd1st_entry), FALSE); - gtk_widget_show (priv->pwd1st_entry); - priv->pwd1st_caption = hildon_caption_new (group, - priv->pwd1st_caption_string, - priv->pwd1st_entry, - NULL, HILDON_CAPTION_OPTIONAL); - - hildon_caption_set_separator (HILDON_CAPTION(priv->pwd1st_caption), ""); - gtk_entry_set_visibility (GTK_ENTRY (priv->pwd1st_entry), FALSE); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG (dialog)->vbox), - priv->pwd1st_caption, TRUE, TRUE, 0); - gtk_widget_show (priv->pwd1st_caption); - - /* Create the password verify field */ - priv->pwd2nd_entry = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); - if ((atk_aux = gtk_widget_get_accessible(priv->pwd2nd_entry))) - { - atk_object_set_name(atk_aux, "New Passwd"); - } - - -#ifdef MAEMO_GTK - g_object_set (priv->pwd2nd_entry, "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL); -#endif - - gtk_widget_show (priv->pwd2nd_entry); - priv->pwd2nd_caption = hildon_caption_new (group, - priv->pwd2nd_caption_string, - priv->pwd2nd_entry, - NULL, HILDON_CAPTION_OPTIONAL); - hildon_caption_set_separator (HILDON_CAPTION (priv->pwd2nd_caption), ""); - gtk_entry_set_visibility (GTK_ENTRY (priv->pwd2nd_entry), FALSE); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG (dialog)->vbox), - priv->pwd2nd_caption, TRUE, TRUE, 0); - gtk_widget_show (priv->pwd2nd_caption); - - /* Set dialog title */ - gtk_window_set_title (GTK_WINDOW (dialog), - _(priv->protection - ? HILDON_SET_MODIFY_PASSWORD_DIALOG_TITLE - : HILDON_SET_PASSWORD_DIALOG_TITLE)); - - /* Create the OK/CANCEL buttons */ - gtk_dialog_add_button (GTK_DIALOG (dialog), _(priv->protection - ? HILDON_SET_MODIFY_PASSWORD_DIALOG_OK - : HILDON_SET_PASSWORD_DIALOG_OK), GTK_RESPONSE_OK); - - gtk_widget_show_all (GTK_DIALOG (dialog)->vbox); - gtk_widget_show_all (GTK_DIALOG (dialog)->action_area); - - /* Ensure group is freed when all its contents have been removed */ - g_object_unref (group); -} - -static void -hildon_set_password_dialog_class_init (HildonSetPasswordDialogClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - parent_class = g_type_class_peek_parent (class); - - /* Override virtual methods */ - object_class->set_property = hildon_set_password_set_property; - object_class->get_property = hildon_set_password_get_property; - - /* Install new properties */ - g_object_class_install_property (object_class, - PROP_MESSAGE, - g_param_spec_string ("message", - "Message", - "A message to display to the user", - NULL, - G_PARAM_READWRITE)); - - /** - * HildonSetPasswordDialog:modify-protection: - * - * Password type. - */ - g_object_class_install_property (object_class, - PROP_HILDON_PASSWORD_DIALOG, - g_param_spec_boolean ("modify-protection", - "Password type", - "Set type to dialog", - TRUE, - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_READWRITE)); - - /** - * HildonSetPasswordDialog:password: - * - * Content of the password field. - */ - g_object_class_install_property (object_class, - PROP_PASSWORD, - g_param_spec_string ("password", - "Password content", - "Set content to dialog", - "DEFAULT", - G_PARAM_READWRITE)); - - /* Install private structure */ - g_type_class_add_private (class, - sizeof (HildonSetPasswordDialogPrivate)); -} - -static void -hildon_set_password_dialog_init (HildonSetPasswordDialog *dialog) -{ - /* Most of the initializations are done in create_contents() - after the 'modify_protection' property has been set */ - - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); -} - - -/* We come here when response button is clicked and dialog - is used to change existing password. */ -static void -hildon_set_password_response_change (GtkDialog *dialog, - gint arg1, - gpointer unused) -{ - GtkEntry *pwd1st_entry; - GtkEntry *pwd2nd_entry; - gchar *text1; - gchar *text2; - HildonNote *note; - gint i; - HildonSetPasswordDialogPrivate *priv; - - priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - /* Password and verification */ - pwd1st_entry = GTK_ENTRY (gtk_bin_get_child - (GTK_BIN (priv->pwd1st_caption))); - pwd2nd_entry = GTK_ENTRY (gtk_bin_get_child - (GTK_BIN (priv->pwd2nd_caption))); - text1 = GTK_ENTRY (pwd1st_entry)->text; - text2 = GTK_ENTRY (pwd2nd_entry)->text; - - /* User accepted the dialog */ - if (arg1 == GTK_RESPONSE_OK) { - /* Is the checkbox marked, so password protection is still in use? */ - if (hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->checkbox))){ - /* Yes, Something is given as password as well? */ - if (text1[0] != '\0') { - if (strcmp (text1, text2) == 0) { - /* Passwords match, so accept change password */ - priv->protection = TRUE; - - } else if (text2[0] == '\0') { - /* Second field is empty, so show error, but don't clear fields */ - g_signal_stop_emission_by_name (G_OBJECT(dialog), - "response"); - - hildon_banner_show_information (GTK_WIDGET (dialog), NULL, - c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); - - gtk_widget_grab_focus (GTK_WIDGET (pwd2nd_entry)); - - } else { - /* Error: Passwords don't match, so start over */ - g_signal_stop_emission_by_name (G_OBJECT(dialog), - "response"); - - gtk_entry_set_text (GTK_ENTRY (pwd1st_entry), ""); - gtk_entry_set_text (GTK_ENTRY (pwd2nd_entry), ""); - - hildon_banner_show_information (GTK_WIDGET (dialog), NULL, - c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); - - gtk_widget_grab_focus (GTK_WIDGET (pwd1st_entry)); - } - } else { - /* No, the password is empty */ - g_signal_stop_emission_by_name (G_OBJECT (dialog), "response"); - - if (text2[0] == '\0') { - /* Error: Both fields are empty */ - hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_EMPTY)); - } else { - /* Error: Second field doesn't match - the empty first field, so start over */ - hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); - gtk_entry_set_text (GTK_ENTRY (pwd2nd_entry), ""); - } - - gtk_widget_grab_focus (GTK_WIDGET (pwd1st_entry)); - } - } else { - /* No, user wants to remove password protection. - Confirm remove password protection */ - note = HILDON_NOTE (hildon_note_new_confirmation - (GTK_WINDOW (dialog), - c_(HILDON_SET_PASSWORD_DIALOG_REMOVE_PROTECTION))); - - hildon_note_set_button_texts - (HILDON_NOTE (note), - c_(HILDON_REMOVE_PROTECTION_CONFIRMATION_REMOVE), - c_(HILDON_REMOVE_PROTECTION_CONFIRMATION_CANCEL)); - - /* Display confirmation note */ - i = gtk_dialog_run (GTK_DIALOG (note)); - - gtk_widget_destroy (GTK_WIDGET (note)); - - if (i == GTK_RESPONSE_OK) - /* Remove password protection */ - priv->protection = FALSE; - else { - /* Remove password protection cancelled */ - priv->protection = TRUE; - g_signal_stop_emission_by_name (G_OBJECT(dialog), "response"); - } - } - - } else { - /* Watch out for fading boolean values */ - priv->protection = TRUE; - } -} - -/* We come here when response button is clicked and dialog - is used to set new password. */ -static void -hildon_set_password_response_set (GtkDialog *dialog, - gint arg1, - gpointer unused) -{ - GtkEntry *pwd1st_entry; - GtkEntry *pwd2nd_entry; - gchar *text1; - gchar *text2; - - HildonSetPasswordDialogPrivate *priv; - - priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - /* Password and confirmation */ - pwd1st_entry = GTK_ENTRY (gtk_bin_get_child - (GTK_BIN (priv->pwd1st_caption))); - - pwd2nd_entry = GTK_ENTRY (gtk_bin_get_child - (GTK_BIN (priv->pwd2nd_caption))); - - text1 = GTK_ENTRY (pwd1st_entry)->text; - text2 = GTK_ENTRY (pwd2nd_entry)->text; - - if (arg1 == GTK_RESPONSE_OK) { - /* User provided something for password? */ - if (text1[0] != '\0') { - if (strcmp (text1, text2) == 0) { - /* Passwords match, so accept set password */ - priv->protection = TRUE; - - } else if (text2[0] == '\0') { - /* Second field is empty, so show error, - but don't clear the fields */ - g_signal_stop_emission_by_name (G_OBJECT(dialog), "response"); - hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); - - gtk_widget_grab_focus (GTK_WIDGET (priv->pwd2nd_entry)); - - } else { - /* Error: Passwords don't match, so start over */ - g_signal_stop_emission_by_name (G_OBJECT(dialog), "response"); - gtk_entry_set_text (GTK_ENTRY (pwd1st_entry), ""); - gtk_entry_set_text (GTK_ENTRY (pwd2nd_entry), ""); - hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); - - gtk_widget_grab_focus (GTK_WIDGET (priv->pwd1st_entry)); - } - } else { - /* First field is empty */ - g_signal_stop_emission_by_name (G_OBJECT (dialog), "response"); - if (text2[0] == '\0') { - /* Error: Both fields are empty */ - hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_EMPTY)); - } else { - /* Error: Second field doesn't match - the empty first field, so start over */ - hildon_banner_show_information (GTK_WIDGET (dialog), NULL, c_(HILDON_SET_PASSWORD_DIALOG_MISMATCH)); - gtk_entry_set_text (GTK_ENTRY (pwd2nd_entry), ""); - } - - gtk_widget_grab_focus (GTK_WIDGET (pwd1st_entry)); - } - } else { - /* Watch out for fading boolean values */ - priv->protection = FALSE; - } -} - -static void -hildon_checkbox_toggled (GtkWidget *widget, - gpointer dialog) -{ - HildonSetPasswordDialogPrivate *priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - gboolean active; - - g_assert (priv); - - /* If the user enabled/disabled the password protection feature - we enable/disable password entries accordingly */ - active = hildon_check_button_get_active (HILDON_CHECK_BUTTON (widget)); - gtk_widget_set_sensitive (GTK_WIDGET (priv->pwd1st_entry), active); - gtk_widget_set_sensitive (GTK_WIDGET (priv->pwd2nd_entry), active); -} - -/** - * hildon_set_password_dialog_get_type: - * - * Returns GType for HildonPasswordDialog as produced by - * g_type_register_static(). - * - * Returns: HildonSetPasswordDialog type - */ -GType G_GNUC_CONST -hildon_set_password_dialog_get_type (void) -{ - static GType dialog_type = 0; - - if (! dialog_type) { - static const GTypeInfo dialog_info = { - sizeof (HildonSetPasswordDialogClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_set_password_dialog_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonSetPasswordDialog), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_set_password_dialog_init - }; - - dialog_type = g_type_register_static (GTK_TYPE_DIALOG, - "HildonSetPasswordDialog", - &dialog_info, 0); - } - - return dialog_type; -} - -/** - * hildon_set_password_dialog_new: - * @parent: parent window; can be NULL - * @modify_protection: TRUE creates a new change password dialog and FALSE - * creates a new set password dialog - * - * Constructs a new HildonSetPasswordDialog. - * - * Returns: a new #GtkWidget of type HildonSetPasswordDialog - */ -GtkWidget* -hildon_set_password_dialog_new (GtkWindow *parent, - gboolean modify_protection) -{ - return hildon_set_password_dialog_new_with_default (parent, "", modify_protection); -} - -/** - * hildon_set_password_dialog_new_with_default: - * @parent: parent window; can be NULL - * @password: a default password to be shown in password field - * @modify_protection: TRUE creates a new change password dialog and FALSE - * creates a new set password dialog - * - * Same as #hildon_set_password_dialog_new, but with a default password - * in password field. - * - * Returns: a new #GtkWidget of type HildonSetPasswordDialog - */ - -GtkWidget* -hildon_set_password_dialog_new_with_default (GtkWindow *parent, - const gchar *password, - gboolean modify_protection) -{ - GtkWidget *dialog = g_object_new (HILDON_TYPE_SET_PASSWORD_DIALOG, - "modify_protection", modify_protection, - "password", password, NULL); - - if (parent != NULL) { - gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); - } - - return dialog; -} - -/** - * hildon_set_password_dialog_get_password: - * @dialog: pointer to HildonSetPasswordDialog - * - * Returns current password. - * - * Returns: changed password ( if the dialog is successfully - * accepted with 'OK' ( and when the check box is 'ON' ( in Change Password - * Dialog )) - */ -const gchar* -hildon_set_password_dialog_get_password (HildonSetPasswordDialog *dialog) -{ - HildonSetPasswordDialogPrivate *priv; - - g_return_val_if_fail (HILDON_IS_SET_PASSWORD_DIALOG (dialog), NULL); - - priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - return GTK_ENTRY (priv->pwd1st_entry)->text; -} - -/** - * hildon_set_password_dialog_get_protected: - * @dialog: pointer to HildonSetPasswordDialog - * - * Returns the protection mode. - * - * Returns: password protection mode ( TRUE when the protection is - * 'ON' and FALSE when the protection is 'OFF' ) - */ -gboolean -hildon_set_password_dialog_get_protected (HildonSetPasswordDialog *dialog) -{ - HildonSetPasswordDialogPrivate *priv; - - g_return_val_if_fail (HILDON_IS_SET_PASSWORD_DIALOG (dialog), FALSE); - - priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - return priv->protection; -} - -/** - * hildon_set_password_dialog_set_message: - * @dialog: the dialog - * @message: the message or some other descriptive text to be set - * - * Sets the optional descriptive text. - */ -void -hildon_set_password_dialog_set_message (HildonSetPasswordDialog *dialog, - const gchar *message) -{ - HildonSetPasswordDialogPrivate *priv = NULL; - - g_return_if_fail (HILDON_IS_SET_PASSWORD_DIALOG (dialog)); - - priv = HILDON_SET_PASSWORD_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - gtk_label_set_text (priv->message_label, message); -} diff --git a/hildon/hildon-set-password-dialog.h b/hildon/hildon-set-password-dialog.h deleted file mode 100644 index 1862d5c..0000000 --- a/hildon/hildon-set-password-dialog.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_SET_PASSWORD_DIALOG_H__ -#define __HILDON_SET_PASSWORD_DIALOG_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_SET_PASSWORD_DIALOG \ - (hildon_set_password_dialog_get_type()) - -#define HILDON_SET_PASSWORD_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_SET_PASSWORD_DIALOG,\ - HildonSetPasswordDialog)) - -#define HILDON_SET_PASSWORD_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), HILDON_TYPE_SET_PASSWORD_DIALOG, \ - HildonSetPasswordDialogClass)) - -#define HILDON_IS_SET_PASSWORD_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_SET_PASSWORD_DIALOG)) - -#define HILDON_IS_SET_PASSWORD_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_SET_PASSWORD_DIALOG)) - -typedef struct _HildonSetPasswordDialog HildonSetPasswordDialog; - -typedef struct _HildonSetPasswordDialogClass HildonSetPasswordDialogClass; - -struct _HildonSetPasswordDialog -{ - GtkDialog parent; -}; - -struct _HildonSetPasswordDialogClass -{ - GtkDialogClass parent_class; -}; - -GtkWidget* -hildon_set_password_dialog_new (GtkWindow *parent, - gboolean modify_protection); - -GtkWidget* -hildon_set_password_dialog_new_with_default (GtkWindow *parent, - const gchar *password, - gboolean modify_protection); - -GType G_GNUC_CONST -hildon_set_password_dialog_get_type (void); - -const gchar* -hildon_set_password_dialog_get_password (HildonSetPasswordDialog *dialog); - -gboolean -hildon_set_password_dialog_get_protected (HildonSetPasswordDialog *dialog); - -void -hildon_set_password_dialog_set_message (HildonSetPasswordDialog *dialog, - const gchar *message); - -G_END_DECLS - -#endif /* __HILDON_SET_PASSWORD_DIALOG_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-sort-dialog-private.h b/hildon/hildon-sort-dialog-private.h deleted file mode 100644 index 788660e..0000000 --- a/hildon/hildon-sort-dialog-private.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_SORT_DIALOG_PRIVATE_H__ -#define __HILDON_SORT_DIALOG_PRIVATEH__ - -G_BEGIN_DECLS - -#define HILDON_SORT_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), HILDON_TYPE_SORT_DIALOG, HildonSortDialogPrivate)); - -typedef struct _HildonSortDialogPrivate HildonSortDialogPrivate; - -struct _HildonSortDialogPrivate -{ - /* Sort category widgets */ - GtkWidget *combo_key; - GtkWidget *caption_key; - - /* Sort order widgets */ - GtkWidget *combo_order; - GtkWidget *caption_order; - - /* Index value counter */ - gint index_counter; - - /* If the current order displayed is reversed */ - gboolean reversed; - - /* An array for each key representing if a key should be reverse-sorted */ - gboolean *key_reversed; -}; - -G_END_DECLS - -#endif /* __HILDON_SORT_DIALOG_PRIVATE_H__ */ diff --git a/hildon/hildon-sort-dialog.c b/hildon/hildon-sort-dialog.c deleted file mode 100644 index 75ba953..0000000 --- a/hildon/hildon-sort-dialog.c +++ /dev/null @@ -1,589 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-sort-dialog - * @short_description: A widget for defining the sorting order of items. - * - * HildonSortDialog is used to define an order (ascending/descending) - * and a field by which items are sorted in a list. The combo boxes - * display the current value when the dialog is opened. - * - * <note> - * <para> - * #HildonSortDialog has been deprecated since Hildon 2.2 - * See <link linkend="hildon-migrating-sort-dialogs">Migrating Sort Dialogs</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <title>An example for using HildonSortDialog</title> - * <programlisting> - * HildonSortDialog *sort_dialog = HILDON_SORT_DIALOG (hildon_sort_dialog_new (parent)); - * <!-- --> - * gint response_id, add_sort_index; - * <!-- --> - * sort_by[0] = STR_SORT_BY_DATE; - * sort_by[1] = STR_SORT_BY_NAME; - * sort_by[2] = STR_SORT_BY_SIZE; - * sort_by[3] = NULL; - * <!-- --> - * sorting_order[0] = STR_SORTING_ORDER_ASCENDING; - * sorting_order[1] = STR_SORTING_ORDER_DESCENDING; - * sorting_order[2] = NULL; - * <!-- --> - * add_sort_index = hildon_sort_dialog_add_sort_key (sort_dialog, STR_SORT_BY_DATE); - * <!-- --> - * hildon_sort_dialog_add_sort_key (sort_dialog, STR_SORT_BY_NAME); - * <!-- --> - * hildon_sort_dialog_add_sort_key (sort_dialog, STR_SORT_BY_SIZE); - * <!-- --> - * if (dialog.first_time_clicked == TRUE) - * { - * hildon_sort_dialog_set_sort_key (sort_dialog, add_sort_index); - * } - * <!-- --> - * if (dialog.first_time_clicked == FALSE) - * { - * hildon_sort_dialog_set_sort_key (sort_dialog, dialog.sort_key); - * hildon_sort_dialog_set_sort_order (sort_dialog, dialog.sort_order); - * } - * <!-- --> - * gtk_widget_show (GTK_WIDGET (sort_dialog)); - * <!-- --> - * response_id = gtk_dialog_run (GTK_DIALOG (sort_dialog)); - * <!-- --> - * if (response_id == GTK_RESPONSE_OK) - * { - * dialog.sort_key = hildon_sort_dialog_get_sort_key (sort_dialog); - * <!-- --> - * gtk_label_set_text (GTK_LABEL (dialog.label1), sort_by [dialog.sort_key]); - * <!-- --> - * dialog.sort_order = hildon_sort_dialog_get_sort_order (sort_dialog); - * <!-- --> - * gtk_label_set_text (GTK_LABEL (dialog.label2), sorting_order [dialog.sort_order]); - * <!-- --> - * dialog.first_time_clicked = FALSE; - * } - * </programlisting> - * </example> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <libintl.h> - -#include "hildon-sort-dialog.h" -#include "hildon-caption.h" -#include "hildon-sort-dialog-private.h" -#include "hildon-stock.h" - -#define _(String) \ - dgettext("hildon-libs", String) - -static GtkDialogClass* parent_class; - -static void -hildon_sort_dialog_class_init (HildonSortDialogClass *class); - -static void -hildon_sort_dialog_init (HildonSortDialog *widget); - -static void -hildon_sort_dialog_set_property (GObject * object, - guint prop_id, - const GValue *value, - GParamSpec * pspec); - -static void -hildon_sort_dialog_get_property (GObject *object, - guint prop_id, - GValue * value, - GParamSpec * pspec); - -static void -reconstruct_combo (HildonSortDialog *dialog, - gboolean remove, - gboolean reversed); - -static void -sort_key_changed (GtkWidget *widget, - HildonSortDialog *dialog); - -static void -hildon_sort_dialog_finalize (GObject *object); - -static gint -hildon_sort_dialog_add_sort_key_with_sorting (HildonSortDialog *dialog, - const gchar *sort_key, - gboolean sorting); - -enum -{ - PROP_0, - PROP_SORT_KEY, - PROP_SORT_ORDER -}; - -static void -sort_key_changed (GtkWidget *widget, - HildonSortDialog *dialog) -{ - g_return_if_fail (HILDON_IS_SORT_DIALOG (dialog)); - - HildonSortDialogPrivate *priv = HILDON_SORT_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - gint index = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); - g_return_if_fail (index < priv->index_counter && index >= 0); - - if (priv->key_reversed [index] != priv->reversed) { - reconstruct_combo (dialog, TRUE, priv->key_reversed [index]); - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo_order), 0); - } - - priv->reversed = priv->key_reversed [index]; -} - -/* Initialises the sort dialog class. */ -static void -hildon_sort_dialog_class_init (HildonSortDialogClass *class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (class); - parent_class = g_type_class_peek_parent (class); - g_type_class_add_private (class, sizeof (HildonSortDialogPrivate)); - - gobject_class->set_property = hildon_sort_dialog_set_property; - gobject_class->get_property = hildon_sort_dialog_get_property; - gobject_class->finalize = (gpointer) hildon_sort_dialog_finalize; - - /** - * HildonSortDialog:sort-key: - * - * The currently active sort key. - */ - g_object_class_install_property (gobject_class, PROP_SORT_KEY, - g_param_spec_int ("sort-key", - "Sort Key", - "The currently active sort key", - G_MININT, - G_MAXINT, - 0, G_PARAM_READWRITE)); - - /** - * HildonSortDialog:sort-order: - * - * The sort order for the currently active sort key. - */ - g_object_class_install_property (gobject_class, PROP_SORT_ORDER, - g_param_spec_enum ("sort-order", - "Sort Order", - "The current sorting order", - GTK_TYPE_SORT_TYPE, - GTK_SORT_ASCENDING, - G_PARAM_READWRITE)); -} - -static gint -hildon_sort_dialog_add_sort_key_with_sorting (HildonSortDialog *dialog, - const gchar *sort_key, - gboolean sorting) -{ - HildonSortDialogPrivate *priv; - - g_return_val_if_fail (HILDON_IS_SORT_DIALOG (dialog), -1); - g_return_val_if_fail (sort_key != NULL, -1); - - priv = HILDON_SORT_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - gboolean *new_array = g_malloc (sizeof (gboolean) * (priv->index_counter + 1)); - - /* Rewrite the old values */ - int i = 0; - for (i = 0; i < priv->index_counter; i++) - new_array [i] = priv->key_reversed [i]; - - new_array [priv->index_counter] = sorting; - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->combo_key), sort_key); - - /* Free the old one and reassign */ - if (priv->key_reversed != NULL) - g_free (priv->key_reversed); - priv->key_reversed = new_array; - - return priv->index_counter++; -} - -static void -reconstruct_combo (HildonSortDialog *dialog, - gboolean remove, - gboolean reversed) -{ - HildonSortDialogPrivate *priv; - priv = HILDON_SORT_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - if (remove) { - gtk_combo_box_remove_text (GTK_COMBO_BOX (priv->combo_order), 1); - gtk_combo_box_remove_text (GTK_COMBO_BOX (priv->combo_order), 0); - } - - if (reversed) { - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->combo_order), _("ckdg_va_sort_descending")); - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->combo_order), _("ckdg_va_sort_ascending")); - } else { - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->combo_order), _("ckdg_va_sort_ascending")); - gtk_combo_box_append_text (GTK_COMBO_BOX (priv->combo_order), _("ckdg_va_sort_descending")); - } -} - -static void -hildon_sort_dialog_init (HildonSortDialog * dialog) -{ - HildonSortDialogPrivate *priv; - GtkSizeGroup *group; - - g_assert(HILDON_IS_SORT_DIALOG (dialog)); - - priv = HILDON_SORT_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - priv->index_counter = 0; - priv->reversed = FALSE; - priv->key_reversed = NULL; - - group = GTK_SIZE_GROUP (gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL)); - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - gtk_window_set_title (GTK_WINDOW (dialog), _("ckdg_ti_sort")); - - /* Tab one */ - priv->combo_key = gtk_combo_box_new_text (); - priv->caption_key = hildon_caption_new(group, _("ckdg_fi_sort_field"), priv->combo_key, - NULL, HILDON_CAPTION_OPTIONAL); - hildon_caption_set_separator(HILDON_CAPTION (priv->caption_key), ""); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), - priv->caption_key, FALSE, FALSE, 0); - - /* Tab two */ - priv->combo_order = gtk_combo_box_new_text (); - reconstruct_combo (dialog, FALSE, FALSE); - - priv->caption_order = hildon_caption_new (group, _("ckdg_fi_sort_order"), - priv->combo_order, - NULL, HILDON_CAPTION_OPTIONAL); - hildon_caption_set_separator(HILDON_CAPTION(priv->caption_order), ""); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), - priv->caption_order, FALSE, FALSE, 0); - - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo_key), 0); - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo_order), 0); - g_signal_connect (G_OBJECT (priv->combo_key), "changed", (gpointer) sort_key_changed, dialog); - - /* Create the OK/CANCEL buttons */ - (void) gtk_dialog_add_button (GTK_DIALOG(dialog), - HILDON_STOCK_SORT, GTK_RESPONSE_OK); - /* FIXME: Hardcoded sizes are bad */ - gtk_window_resize (GTK_WINDOW (dialog), 370, 100); - gtk_widget_show_all (GTK_DIALOG (dialog)->vbox); - - g_object_unref (group); /* Captions now own their references to sizegroup */ -} - -/** - * hildon_sort_dialog_get_type: - * - * Returns GType for HildonSortDialog as produced by - * g_type_register_static(). - * - * Returns: HildonSortDialog type - */ -GType G_GNUC_CONST -hildon_sort_dialog_get_type (void) -{ - static GType dialog_type = 0; - - if (!dialog_type) { - static const GTypeInfo dialog_info = { - sizeof (HildonSortDialogClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_sort_dialog_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonSortDialog), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_sort_dialog_init - }; - - dialog_type = g_type_register_static (GTK_TYPE_DIALOG, - "HildonSortDialog", - &dialog_info, 0); - } - return dialog_type; -} - -/** - * hildon_sort_dialog_new: - * @parent: widget to be transient for, or NULL if none - * - * HildonSortDialog contains two HildonCaptions with combo boxes. - * - * Returns: pointer to a new @HildonSortDialog widget - */ -GtkWidget* -hildon_sort_dialog_new (GtkWindow * parent) -{ - GtkWidget *sort_dialog = g_object_new (HILDON_TYPE_SORT_DIALOG, NULL); - - if (parent) - gtk_window_set_transient_for (GTK_WINDOW (sort_dialog), parent); - - return sort_dialog; -} - -/** - * hildon_sort_dialog_get_sort_key: - * @dialog: the #HildonSortDialog widget - * - * Gets index to currently active sort key. - * - * Returns: an integer which is the index value of the "Sort by" - * field - */ -gint -hildon_sort_dialog_get_sort_key (HildonSortDialog *dialog) -{ - GtkWidget *combo_key; - HildonSortDialogPrivate *priv; - - g_return_val_if_fail (HILDON_IS_SORT_DIALOG (dialog), -1); - - priv = HILDON_SORT_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - combo_key = gtk_bin_get_child (GTK_BIN (priv->caption_key)); - - return gtk_combo_box_get_active (GTK_COMBO_BOX (combo_key)); -} - -/** - * hildon_sort_dialog_get_sort_order: - * @dialog: the #HildonSortDialog widget - * - * Gets current sorting order from "Sort order" field. - * - * Returns: current sorting order as #GtkSortType - */ -GtkSortType -hildon_sort_dialog_get_sort_order (HildonSortDialog *dialog) -{ - GtkWidget *combo_order; - HildonSortDialogPrivate *priv; - - g_return_val_if_fail (HILDON_IS_SORT_DIALOG (dialog), 0); - - priv = HILDON_SORT_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - combo_order = gtk_bin_get_child (GTK_BIN (priv->caption_order)); - - gint sort_order = gtk_combo_box_get_active (GTK_COMBO_BOX (combo_order)); - - if (priv->reversed) - return (sort_order == 0) ? 1 : 0; - else - return sort_order; -} - -/** - * hildon_sort_dialog_set_sort_key: - * @dialog: the #HildonSortDialog widget - * @key: combo box's index value - * - * Sets the index value of the #HildonSortDialog widget. - */ -void -hildon_sort_dialog_set_sort_key (HildonSortDialog * dialog, - gint key) -{ - GtkWidget *combo_key; - HildonSortDialogPrivate *priv; - - g_return_if_fail (HILDON_IS_SORT_DIALOG (dialog)); - - priv = HILDON_SORT_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - combo_key = gtk_bin_get_child (GTK_BIN (priv->caption_key)); - gtk_combo_box_set_active (GTK_COMBO_BOX (combo_key), key); - - g_object_notify (G_OBJECT (dialog), "sort-key"); -} - -/** - * hildon_sort_dialog_set_sort_order: - * @dialog: the #HildonSortDialog widget - * @order: combo box's index value - * - * Sets the index value of the #HildonSortDialog widget. - */ -void -hildon_sort_dialog_set_sort_order (HildonSortDialog *dialog, - GtkSortType order) -{ - GtkWidget *combo_order; - HildonSortDialogPrivate *priv; - - g_return_if_fail (HILDON_IS_SORT_DIALOG (dialog)); - - priv = HILDON_SORT_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - combo_order = gtk_bin_get_child (GTK_BIN (priv->caption_order)); - - if (priv->reversed) - order = (order == 0) ? 1 : 0; - - gtk_combo_box_set_active (GTK_COMBO_BOX (combo_order), order); - - g_object_notify (G_OBJECT (dialog), "sort-order"); -} - -/** - * hildon_sort_dialog_add_sort_key: - * @dialog: the #HildonSortDialog widget - * @sort_key: combo box's index value - * - * Adds a new sort key and returns the respective index in - * sort key combobox. - * - * Returns: an integer which is the index of the added combo box's - * item - */ -gint -hildon_sort_dialog_add_sort_key (HildonSortDialog *dialog, - const gchar *sort_key) -{ - return hildon_sort_dialog_add_sort_key_with_sorting (dialog, sort_key, FALSE); -} - -/** - * hildon_sort_dialog_add_sort_key_reversed: - * @dialog: the #HildonSortDialog widget - * @sort_key: combo box's index value - * - * Adds a new sort key and returns the respective index in - * sort key combobox. The default sort order for this key is reversed (Descending first). - * - * Returns: an integer which is the index of the added combo box's - * item - * - */ -gint -hildon_sort_dialog_add_sort_key_reversed (HildonSortDialog *dialog, - const gchar *sort_key) -{ - return hildon_sort_dialog_add_sort_key_with_sorting (dialog, sort_key, TRUE); -} - -static void -hildon_sort_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonSortDialog *dialog; - - dialog = HILDON_SORT_DIALOG(object); - - switch (prop_id) { - - case PROP_SORT_KEY: - hildon_sort_dialog_set_sort_key (dialog, g_value_get_int (value)); - break; - - case PROP_SORT_ORDER: - hildon_sort_dialog_set_sort_order (dialog, g_value_get_enum (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -hildon_sort_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - HildonSortDialog *dialog; - - dialog = HILDON_SORT_DIALOG (object); - - switch (prop_id) { - - case PROP_SORT_KEY: - g_value_set_int (value, hildon_sort_dialog_get_sort_key (dialog)); - break; - - case PROP_SORT_ORDER: - g_value_set_enum (value, hildon_sort_dialog_get_sort_order (dialog)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - - } -} - -static void -hildon_sort_dialog_finalize (GObject *object) -{ - HildonSortDialogPrivate *priv; - HildonSortDialog *dialog; - - dialog = HILDON_SORT_DIALOG (object); - priv = HILDON_SORT_DIALOG_GET_PRIVATE (dialog); - g_assert (priv); - - if (priv != NULL && priv->key_reversed != NULL) - g_free (priv->key_reversed); - - if (G_OBJECT_CLASS (parent_class)->finalize) - G_OBJECT_CLASS (parent_class)->finalize(object); -} - - diff --git a/hildon/hildon-sort-dialog.h b/hildon/hildon-sort-dialog.h deleted file mode 100644 index 761c46e..0000000 --- a/hildon/hildon-sort-dialog.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_SORT_DIALOG_H__ -#define __HILDON_SORT_DIALOG_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -typedef struct _HildonSortDialog HildonSortDialog; - -typedef struct _HildonSortDialogClass HildonSortDialogClass; - - -#define HILDON_TYPE_SORT_DIALOG \ - (hildon_sort_dialog_get_type()) - -#define HILDON_SORT_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_SORT_DIALOG, HildonSortDialog)) - -#define HILDON_SORT_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), HILDON_TYPE_SORT_DIALOG, \ - HildonSortDialogClass)) - -#define HILDON_IS_SORT_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_SORT_DIALOG)) - -#define HILDON_IS_SORT_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_SORT_DIALOG)) - -#define HILDON_SORT_DIALOG_GET_CLASS(obj) \ - ((HildonSortDialogClass *) G_OBJECT_GET_CLASS(obj)) - -struct _HildonSortDialog -{ - GtkDialog parent; -}; - -struct _HildonSortDialogClass -{ - GtkDialogClass parent_class; -}; - -GType G_GNUC_CONST -hildon_sort_dialog_get_type (void); - -GtkWidget* -hildon_sort_dialog_new (GtkWindow *parent); - -gint -hildon_sort_dialog_get_sort_key (HildonSortDialog *dialog); - -GtkSortType -hildon_sort_dialog_get_sort_order (HildonSortDialog *dialog); - -void -hildon_sort_dialog_set_sort_key (HildonSortDialog *dialog, - int key); - -void -hildon_sort_dialog_set_sort_order (HildonSortDialog *dialog, - GtkSortType order); - -gint -hildon_sort_dialog_add_sort_key (HildonSortDialog *dialog, - const gchar *sort_key); - -gint -hildon_sort_dialog_add_sort_key_reversed (HildonSortDialog *dialog, - const gchar *sort_key); - -G_END_DECLS - -#endif /* __HILDON_SORT_DIALOG_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-stackable-window.c b/hildon/hildon-stackable-window.c index c10d433..1f6c0d5 100644 --- a/hildon/hildon-stackable-window.c +++ b/hildon/hildon-stackable-window.c @@ -94,8 +94,6 @@ * </example> */ -#undef HILDON_DISABLE_DEPRECATED - #include <X11/X.h> #include <X11/Xatom.h> #include <gdk/gdkx.h> @@ -147,22 +145,6 @@ hildon_stackable_window_get_stack (HildonStackableWindow *self) return priv->stack; } -/** - * hildon_stackable_window_set_main_menu: - * @self: a #HildonStackableWindow - * @menu: a #HildonAppMenu to be used for this window - * - * Sets the menu to be used for this window. - * - * Deprecated: Hildon 2.2: use hildon_window_set_app_menu() - **/ -void -hildon_stackable_window_set_main_menu (HildonStackableWindow *self, - HildonAppMenu *menu) -{ - hildon_window_set_app_menu (HILDON_WINDOW (self), menu); -} - static void hildon_stackable_window_map (GtkWidget *widget) { diff --git a/hildon/hildon-stackable-window.h b/hildon/hildon-stackable-window.h index 2e2a712..45f3897 100644 --- a/hildon/hildon-stackable-window.h +++ b/hildon/hildon-stackable-window.h @@ -86,12 +86,6 @@ hildon_stackable_window_get_type (void) G_GNUC_CONST; GtkWidget* hildon_stackable_window_new (void); -#ifndef HILDON_DISABLE_DEPRECATED -void -hildon_stackable_window_set_main_menu (HildonStackableWindow *self, - HildonAppMenu *menu); -#endif - HildonWindowStack * hildon_stackable_window_get_stack (HildonStackableWindow *self); diff --git a/hildon/hildon-text-view.c b/hildon/hildon-text-view.c index 1e3b23f..4013c73 100644 --- a/hildon/hildon-text-view.c +++ b/hildon/hildon-text-view.c @@ -47,8 +47,6 @@ * </example> */ -#undef HILDON_DISABLE_DEPRECATED - #include "hildon-text-view.h" #include <math.h> @@ -71,75 +69,6 @@ struct _HildonTextViewPrivate /** - * hildon_text_view_set_buffer: - * @text_view: a #HildonTextView - * @buffer: a #GtkTextBuffer - * - * Sets @buffer as the buffer being displayed by @text_view. The - * previous buffer displayed by the text view is unreferenced, and a - * reference is added to @buffer. If you owned a reference to @buffer - * before passing it to this function, you must remove that reference - * yourself - * - * Since: 2.2 - * - * Deprecated: use gtk_text_view_set_buffer() instead - */ -void -hildon_text_view_set_buffer (HildonTextView *text_view, - GtkTextBuffer *buffer) -{ - g_return_if_fail (HILDON_IS_TEXT_VIEW (text_view)); - g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); - gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), buffer); -} - -/** - * hildon_text_view_get_buffer: - * @text_view: a #HildonTextView - * - * Returns the text buffer in @text_view. The reference count is not - * incremented; the caller of this function won't own a new reference. - * - * Note that the placeholder text (set using - * hildon_gtk_text_view_set_placeholder_text()) is never contained in - * this buffer. - * - * Returns: a #GtkTextBuffer - * - * Since: 2.2 - * - * Deprecated: use gtk_text_view_get_buffer() instead - */ -GtkTextBuffer * -hildon_text_view_get_buffer (HildonTextView *text_view) -{ - g_return_val_if_fail (HILDON_IS_TEXT_VIEW (text_view), NULL); - return gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); -} - -/** - * hildon_text_view_set_placeholder: - * @text_view: a #HildonTextView - * @text: the new text - * - * Sets the placeholder text in @text_view to @text. - * - * Since: 2.2 - * - * Deprecated: use hildon_gtk_text_view_set_placeholder_text() instead - */ -void -hildon_text_view_set_placeholder (HildonTextView *text_view, - const gchar *text) -{ - g_return_if_fail (HILDON_IS_TEXT_VIEW (text_view) && text != NULL); -#ifdef MAEMO_GTK - hildon_gtk_text_view_set_placeholder_text (GTK_TEXT_VIEW (text_view), text); -#endif -} - -/** * hildon_text_view_new: * * Creates a new text view. diff --git a/hildon/hildon-text-view.h b/hildon/hildon-text-view.h index 7337eb5..a67313b 100644 --- a/hildon/hildon-text-view.h +++ b/hildon/hildon-text-view.h @@ -63,19 +63,6 @@ hildon_text_view_get_type (void) G_GNUC_CONST; GtkWidget * hildon_text_view_new (void); -#ifndef HILDON_DISABLE_DEPRECATED -void -hildon_text_view_set_buffer (HildonTextView *text_view, - GtkTextBuffer *buffer); - -GtkTextBuffer * -hildon_text_view_get_buffer (HildonTextView *text_view); - -void -hildon_text_view_set_placeholder (HildonTextView *text_view, - const gchar *text); -#endif - G_END_DECLS #endif /* __HILDON_TEXT_VIEW_H__ */ diff --git a/hildon/hildon-time-editor-private.h b/hildon/hildon-time-editor-private.h deleted file mode 100644 index db51b30..0000000 --- a/hildon/hildon-time-editor-private.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_TIME_EDITOR_PRIVATE_H__ -#define __HILDON_TIME_EDITOR_PRIVATE_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TIME_EDITOR_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj),\ - HILDON_TYPE_TIME_EDITOR, HildonTimeEditorPrivate)); - -/* Indices for h/m/s entries in priv->entries */ -enum { - ENTRY_HOURS, - ENTRY_MINS, - ENTRY_SECS, - - ENTRY_COUNT -}; - -typedef struct _HildonTimeEditorPrivate HildonTimeEditorPrivate; - -struct _HildonTimeEditorPrivate -{ - guint ticks; /* Current duration in seconds */ - - gchar *am_symbol; - gchar *pm_symbol; - - GtkWidget *iconbutton; /* button for icon */ - - GtkWidget *frame; /* frame around the entries */ - GtkWidget *entries[ENTRY_COUNT]; /* h, m, s entries */ - GtkWidget *hm_label; /* between hour and minute */ - GtkWidget *sec_label; /* between minute and second */ - GtkWidget *ampm_label; /* label for showing am or pm */ - - GtkWidget *error_widget; /* field to highlight in idle */ - GtkWidget *ampm_button; /* am/pm change button */ - - - gboolean duration_mode; /* In HildonDurationEditor mode */ - gboolean show_seconds; /* show seconds */ - gboolean show_hours; /* show hours */ - - gboolean ampm_pos_after; /* is am/pm shown after others */ - gboolean clock_24h; /* whether to show a 24h clock */ - gboolean am; /* TRUE == am, FALSE == pm */ - - guint duration_min; /* duration editor ranges */ - guint duration_max; /* duration editor ranges */ - - guint highlight_idle; - gboolean skipper; /* FIXME (MDK): To prevent us from looping inside the validation events. - When set to TRUE further validations (that can happen from-inside other - validations) are being skipped. Nasty hack to cope with a bad design. */ -}; - -G_END_DECLS - -#endif /* __HILDON_TIME_EDITOR_H__ */ diff --git a/hildon/hildon-time-editor.c b/hildon/hildon-time-editor.c deleted file mode 100644 index ea73c79..0000000 --- a/hildon/hildon-time-editor.c +++ /dev/null @@ -1,1930 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-time-editor - * @short_description: A widget used to enter time or duration in hours, minutes, - * and optional seconds. - * @see_also: #HildonTimePicker - * - * HildonTimeEditor is used to edit time or duration. Time mode is - * restricted to normal 24 hour cycle, but Duration mode can select any - * amount of time up to 99 hours. It consists of entries for hours, - * minutes and seconds, and pm/am indicator as well as a button which - * popups a #HildonTimePicker dialog. - * - * <note> - * <para> - * #HildonTimeEditor has been deprecated since Hildon 2.2 and should not - * be used in newly written code. See - * <link linkend="hildon-migrating-time-widgets">Migrating Time Widgets</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <title>HildonTimePicker example</title> - * <programlisting> - * <!-- --> - * editor = hildon_time_editor_new (); - * hildon_time_editor_set_time (editor, h, m, s); - * <!-- --> - * gtk_box_pack_start (..., editor) - * <!-- --> - * hildon_time_editor_get_time (editor, &h, &m, &s); - * <!-- --> - * </programlisting> - * </example> - * - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <time.h> -#include <stdlib.h> -#include <langinfo.h> -#include <libintl.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-time-editor.h" -#include "hildon-defines.h" -#include "hildon-time-picker.h" -#include "hildon-banner.h" -#include "hildon-private.h" -#include "hildon-marshalers.h" -#include "hildon-enum-types.h" -#include "hildon-time-editor-private.h" - -#define _(String) dgettext("hildon-libs", String) - -#define c_(String) dgettext("hildon-common-strings", String) - -#define TICKS(h,m,s) \ - ((h) * 3600 + (m) * 60 + (s)) - -#define TIME_EDITOR_HEIGHT 30 - -#define ICON_PRESSED 4 - -#define ICON_NAME "widgets_time_editor" - -#define ICON_SIZE "timepicker-size" - -#define MIN_DURATION 0 - -#define MAX_DURATION TICKS(99, 59, 59) - -/* Default values for properties */ - -#define HILDON_TIME_EDITOR_TICKS_VALUE 0 - -#define HILDON_TIME_EDITOR_DURATION_MODE FALSE - -#define HILDON_TIME_EDITOR_DURATION_LOWER_VALUE 0 - -#define HILDON_TIME_EDITOR_DURATION_UPPER_VALUE TICKS(99, 59, 59) - -#define HOURS_MAX_24 23 - -#define HOURS_MAX_12 12 - -#define HOURS_MIN_24 0 - -#define HOURS_MIN_12 1 - -#define MINUTES_MAX 59 - -#define SECONDS_MAX 59 - -#define MINUTES_MIN 0 - -#define SECONDS_MIN 0 - -static GtkContainerClass* parent_class; - -enum -{ - PROP_0, - PROP_TICKS, - PROP_DURATION_MODE, - PROP_DURATION_MIN, - PROP_DURATION_MAX, - PROP_SHOW_SECONDS, - PROP_SHOW_HOURS -}; - -/* Signals */ -enum { - TIME_ERROR, - LAST_SIGNAL -}; - -/* Error codes categories */ -enum { - MAX_VALUE, - MIN_VALUE, - WITHIN_RANGE, - NUM_ERROR_CODES -}; - -static guint time_editor_signals[LAST_SIGNAL] = { 0 }; - -static guint hour_errors[NUM_ERROR_CODES] = { - HILDON_DATE_TIME_ERROR_MAX_HOURS, - HILDON_DATE_TIME_ERROR_MIN_HOURS, - HILDON_DATE_TIME_ERROR_EMPTY_HOURS }; - -static guint min_errors[NUM_ERROR_CODES] = { - HILDON_DATE_TIME_ERROR_MAX_MINS, - HILDON_DATE_TIME_ERROR_MIN_MINS, - HILDON_DATE_TIME_ERROR_EMPTY_MINS }; - -static guint sec_errors[NUM_ERROR_CODES] = { - HILDON_DATE_TIME_ERROR_MAX_SECS, - HILDON_DATE_TIME_ERROR_MIN_SECS, - HILDON_DATE_TIME_ERROR_EMPTY_SECS }; - -static void -hildon_time_editor_class_init (HildonTimeEditorClass *editor_class); - -static void -hildon_time_editor_init (HildonTimeEditor *editor); - -static void -hildon_time_editor_finalize (GObject *obj_self); - -static void -hildon_time_editor_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_time_editor_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void -hildon_time_editor_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void -hildon_time_editor_destroy (GtkObject *self); - -static gboolean -hildon_time_editor_entry_focus_out (GtkWidget *widget, - GdkEventFocus *event, - gpointer data); - -static gboolean -hildon_time_editor_entry_focus_in (GtkWidget *widget, - GdkEventFocus *event, - gpointer data); - -static gboolean -hildon_time_editor_time_error (HildonTimeEditor *editor, - HildonDateTimeError type); - -static gboolean -hildon_time_editor_ampm_clicked (GtkWidget *widget, - gpointer data); - -static gboolean -hildon_time_editor_icon_clicked (GtkWidget *widget, - gpointer data); - -static void -hildon_time_editor_size_request (GtkWidget *widget, - GtkRequisition *requisition); - -static void -hildon_time_editor_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static gboolean -hildon_time_editor_focus (GtkWidget *widget, - GtkDirectionType direction); - -static gboolean -hildon_time_editor_entry_keypress (GtkEntry *entry, - GdkEventKey* event, - gpointer user_data); - -static gboolean -hildon_time_editor_check_locale (HildonTimeEditor *editor); - -#ifdef MAEMO_GTK -static void -hildon_time_editor_tap_and_hold_setup (GtkWidget *widget, - GtkWidget *menu, - GtkCallback func, - GtkWidgetTapAndHoldFlags flags); -#endif - -static void -hildon_time_editor_validate (HildonTimeEditor *editor, - gboolean allow_intermediate); - -static void -hildon_time_editor_set_to_current_time (HildonTimeEditor *editor); - -static gboolean -hildon_time_editor_entry_select_all (GtkWidget *widget); - -static void -convert_to_12h (guint *h, - gboolean *am); - -static void -convert_to_24h (guint *h, - gboolean am); - -static void -ticks_to_time (guint ticks, - guint *hours, - guint *minutes, - guint *seconds); - -static void -hildon_time_editor_inserted_text (GtkEditable *editable, - gchar *new_text, - gint new_text_length, - gint *position, - gpointer user_data); - -/** - * hildon_time_editor_get_type: - * - * Initializes and returns the type of a hildon time editor. - * - * Returns: GType of #HildonTimeEditor - */ -GType G_GNUC_CONST -hildon_time_editor_get_type (void) -{ - static GType editor_type = 0; - - if (! editor_type) { - static const GTypeInfo editor_info = { - sizeof(HildonTimeEditorClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_time_editor_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(HildonTimeEditor), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_time_editor_init, - }; - editor_type = g_type_register_static (GTK_TYPE_CONTAINER, - "HildonTimeEditor", - &editor_info, 0); - } - - return editor_type; -} - -static void -hildon_time_editor_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - HildonTimeEditorPrivate *priv; - - g_assert (HILDON_IS_TIME_EDITOR (container)); - g_assert (callback != NULL); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (container); - - g_assert (priv); - - if (! include_internals) - return; - - /* widget that are always shown */ - (*callback) (priv->iconbutton, callback_data); - (*callback) (priv->frame, callback_data); -} - -static void -hildon_time_editor_destroy (GtkObject *self) -{ - HildonTimeEditorPrivate *priv; - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (self); - g_assert (priv); - - if (priv->iconbutton) { - gtk_widget_unparent (priv->iconbutton); - priv->iconbutton = NULL; - } - if (priv->frame) { - gtk_widget_unparent (priv->frame); - priv->frame = NULL; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - GTK_OBJECT_CLASS (parent_class)->destroy (self); -} - -static void -hildon_time_editor_class_init (HildonTimeEditorClass *editor_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (editor_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (editor_class); - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (editor_class); - - parent_class = g_type_class_peek_parent (editor_class); - - g_type_class_add_private (editor_class, sizeof (HildonTimeEditorPrivate)); - - object_class->get_property = hildon_time_editor_get_property; - object_class->set_property = hildon_time_editor_set_property; - widget_class->size_request = hildon_time_editor_size_request; - widget_class->size_allocate = hildon_time_editor_size_allocate; - widget_class->focus = hildon_time_editor_focus; - - container_class->forall = hildon_time_editor_forall; - GTK_OBJECT_CLASS (editor_class)->destroy = hildon_time_editor_destroy; - - object_class->finalize = hildon_time_editor_finalize; - - editor_class->time_error = hildon_time_editor_time_error; - - time_editor_signals[TIME_ERROR] = - g_signal_new ("time-error", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (HildonTimeEditorClass, time_error), - g_signal_accumulator_true_handled, NULL, - _hildon_marshal_BOOLEAN__ENUM, - G_TYPE_BOOLEAN, 1, HILDON_TYPE_DATE_TIME_ERROR); - - /** - * HildonTimeEditor:ticks: - * - * If editor is in duration mode, contains the duration seconds. - * If not, contains seconds since midnight. - */ - g_object_class_install_property (object_class, PROP_TICKS, - g_param_spec_uint ("ticks", - "Duration value", - "Current value of duration", - 0, G_MAXUINT, - HILDON_TIME_EDITOR_TICKS_VALUE, - G_PARAM_READABLE | G_PARAM_WRITABLE) ); - - /** - * HildonTimeEditor:show_seconds: - * - * Controls whether seconds are shown in the editor - */ - g_object_class_install_property (object_class, PROP_SHOW_SECONDS, - g_param_spec_boolean ("show_seconds", - "Show seconds property", - "Controls whether the seconds are shown in the editor", - FALSE, - G_PARAM_READABLE | G_PARAM_WRITABLE) ); - - /** - * HildonTimeEditor:show_hours: - * - * Controls whether hours are shown in the editor - */ - g_object_class_install_property (object_class, PROP_SHOW_HOURS, - g_param_spec_boolean ("show_hours", - "Show hours field", - "Controls whether the hours field is shown in the editor", - TRUE, - G_PARAM_READABLE | G_PARAM_WRITABLE) ); - - /** - * HildonTimeEditor:duration_mode: - * - * Controls whether the TimeEditor is in duration mode - */ - g_object_class_install_property (object_class, PROP_DURATION_MODE, - g_param_spec_boolean ("duration_mode", - "Duration mode", - "Controls whether the TimeEditor is in duration mode", - HILDON_TIME_EDITOR_DURATION_MODE, - G_PARAM_READABLE | G_PARAM_WRITABLE) ); - - /** - * HildonTimeEditor:duration_min: - * - * Minimum allowed duration value. - */ - g_object_class_install_property (object_class, PROP_DURATION_MIN, - g_param_spec_uint ("duration_min", - "Minumum duration value", - "Smallest possible duration value", - MIN_DURATION, MAX_DURATION, - HILDON_TIME_EDITOR_DURATION_LOWER_VALUE, - G_PARAM_READABLE | G_PARAM_WRITABLE) ); - - /** - * HildonTimeEditor:duration_max: - * - * Maximum allowed duration value. - */ - g_object_class_install_property (object_class, PROP_DURATION_MAX, - g_param_spec_uint ("duration_max", - "Maximum duration value", - "Largest possible duration value", - 0, G_MAXUINT, - HILDON_TIME_EDITOR_DURATION_UPPER_VALUE, - G_PARAM_READABLE | G_PARAM_WRITABLE) ); -} - -#ifdef MAEMO_GTK -static void -hildon_time_editor_tap_and_hold_setup (GtkWidget *widget, - GtkWidget *menu, - GtkCallback func, - GtkWidgetTapAndHoldFlags flags) -{ - HildonTimeEditorPrivate *priv = HILDON_TIME_EDITOR_GET_PRIVATE (widget); - gint i; - - /* Forward this tap_and_hold_setup signal to all our child widgets */ - for (i = 0; i < ENTRY_COUNT; i++) - { - gtk_widget_tap_and_hold_setup (priv->entries[i], menu, func, - GTK_TAP_AND_HOLD_NO_SIGNALS); - } - gtk_widget_tap_and_hold_setup (priv->ampm_button, menu, func, - GTK_TAP_AND_HOLD_NO_SIGNALS); - gtk_widget_tap_and_hold_setup (priv->iconbutton, menu, func, - GTK_TAP_AND_HOLD_NONE); -} -#endif - -static void -hildon_time_editor_entry_changed (GtkWidget *widget, - gpointer data) -{ - g_assert (HILDON_IS_TIME_EDITOR (data)); - hildon_time_editor_validate (HILDON_TIME_EDITOR (data), TRUE); -} - -static void -hildon_time_editor_init (HildonTimeEditor *editor) -{ - HildonTimeEditorPrivate *priv; - GtkWidget *hbox, *icon; - gint i; - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - gtk_widget_push_composite_child (); - - /* Setup defaults and create widgets */ - priv->ticks = 0; - priv->show_seconds = FALSE; - priv->show_hours = TRUE; - priv->ampm_pos_after = TRUE; - priv->clock_24h = TRUE; - priv->duration_mode = FALSE; - priv->iconbutton = gtk_button_new(); - priv->ampm_label = gtk_label_new(NULL); - priv->hm_label = gtk_label_new(NULL); - priv->sec_label = gtk_label_new(NULL); - priv->frame = gtk_frame_new(NULL); - priv->ampm_button = gtk_button_new(); - priv->skipper = FALSE; - - icon = gtk_image_new_from_icon_name (ICON_NAME, HILDON_ICON_SIZE_SMALL); - hbox = gtk_hbox_new (FALSE, 0); - - GTK_WIDGET_SET_FLAGS (editor, GTK_NO_WINDOW); - GTK_WIDGET_UNSET_FLAGS (priv->iconbutton, GTK_CAN_FOCUS | GTK_CAN_DEFAULT); - - gtk_container_set_border_width (GTK_CONTAINER(priv->frame), 0); - - gtk_container_add (GTK_CONTAINER (priv->iconbutton), icon); - gtk_container_add (GTK_CONTAINER (priv->ampm_button), priv->ampm_label); - gtk_button_set_relief(GTK_BUTTON (priv->ampm_button), GTK_RELIEF_NONE); - gtk_button_set_focus_on_click (GTK_BUTTON (priv->ampm_button), FALSE); - - /* Create hour, minute and second entries */ - for (i = 0; i < ENTRY_COUNT; i++) - { - priv->entries[i] = gtk_entry_new (); - - /* No frames for entries, so that they all appear to be inside one long entry */ - gtk_entry_set_has_frame (GTK_ENTRY (priv->entries[i]), FALSE); - -#ifdef MAEMO_GTK - /* Set the entries to accept only numeric characters */ - g_object_set (priv->entries[i], "hildon-input-mode", HILDON_GTK_INPUT_MODE_NUMERIC, NULL); -#endif - - /* The entry fields all take exactly two characters */ - gtk_entry_set_max_length (GTK_ENTRY (priv->entries[i]), 2); - gtk_entry_set_width_chars (GTK_ENTRY (priv->entries[i]), 2); - - g_signal_connect (priv->entries[i], "focus-in-event", - G_CALLBACK (hildon_time_editor_entry_focus_in), editor); - g_signal_connect (priv->entries[i], "focus-out-event", - G_CALLBACK (hildon_time_editor_entry_focus_out), editor); - g_signal_connect (priv->entries[i], "key-press-event", - G_CALLBACK (hildon_time_editor_entry_keypress), editor); - g_signal_connect (priv->entries[i], "changed", - G_CALLBACK (hildon_time_editor_entry_changed), editor); - - /* inserted signal sets time */ - g_signal_connect_after (G_OBJECT(priv->entries[i]), "insert_text", - G_CALLBACK (hildon_time_editor_inserted_text), - editor); - } - - /* clicked signal for am/pm label */ - g_signal_connect (G_OBJECT (priv->ampm_button), "clicked", - G_CALLBACK (hildon_time_editor_ampm_clicked), editor); - - /* clicked signal for icon */ - g_signal_connect (G_OBJECT (priv->iconbutton), "clicked", - G_CALLBACK (hildon_time_editor_icon_clicked), editor); - - /* Set ourself as the parent of all the widgets we created */ - gtk_widget_set_parent (priv->iconbutton, GTK_WIDGET(editor)); - gtk_box_pack_start (GTK_BOX (hbox), priv->entries[ENTRY_HOURS], FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), priv->hm_label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), priv->entries[ENTRY_MINS], FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), priv->sec_label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), priv->entries[ENTRY_SECS], FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), priv->ampm_button, FALSE, FALSE, 0); - gtk_misc_set_padding (GTK_MISC (priv->ampm_label), 0, 0); - - gtk_container_add (GTK_CONTAINER (priv->frame), hbox); - - /* Show created widgets */ - gtk_widget_set_parent (priv->frame, GTK_WIDGET(editor)); - gtk_widget_show_all (priv->frame); - gtk_widget_show_all (priv->iconbutton); - - /* Update AM/PM and time separators settings from locale */ - if (! hildon_time_editor_check_locale (editor)) { - /* Using 12h clock */ - priv->clock_24h = FALSE; - } else { - gtk_widget_hide (priv->ampm_button); - } - - if (! priv->show_seconds) { - gtk_widget_hide (priv->sec_label); - gtk_widget_hide (priv->entries[ENTRY_SECS]); - } - - /* set the default time to current time. */ - hildon_time_editor_set_to_current_time (editor); - - gtk_widget_pop_composite_child (); - -#ifdef MAEMO_GTK - g_signal_connect (editor, "tap-and-hold-setup", - G_CALLBACK (hildon_time_editor_tap_and_hold_setup), - NULL); -#endif - -} - -static void -hildon_time_editor_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonTimeEditor *time_editor = HILDON_TIME_EDITOR (object); - - switch (param_id) - { - case PROP_TICKS: - hildon_time_editor_set_ticks (time_editor, g_value_get_uint(value)); - break; - - case PROP_SHOW_SECONDS: - hildon_time_editor_set_show_seconds (time_editor, g_value_get_boolean(value)); - break; - - case PROP_SHOW_HOURS: - hildon_time_editor_set_show_hours (time_editor, g_value_get_boolean(value)); - break; - - case PROP_DURATION_MODE: - hildon_time_editor_set_duration_mode (time_editor, g_value_get_boolean(value)); - break; - - case PROP_DURATION_MIN: - hildon_time_editor_set_duration_min (time_editor, g_value_get_uint(value)); - break; - - case PROP_DURATION_MAX: - hildon_time_editor_set_duration_max (time_editor, g_value_get_uint(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); - break; - } -} - -static void -hildon_time_editor_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - HildonTimeEditor *time_editor = HILDON_TIME_EDITOR (object); - - switch (param_id) - { - - case PROP_TICKS: - g_value_set_uint (value, hildon_time_editor_get_ticks (time_editor)); - break; - - case PROP_SHOW_SECONDS: - g_value_set_boolean (value, hildon_time_editor_get_show_seconds (time_editor)); - break; - - case PROP_SHOW_HOURS: - g_value_set_boolean (value, hildon_time_editor_get_show_hours (time_editor)); - break; - - case PROP_DURATION_MODE: - g_value_set_boolean (value, hildon_time_editor_get_duration_mode (time_editor)); - break; - - case PROP_DURATION_MIN: - g_value_set_uint (value, hildon_time_editor_get_duration_min (time_editor)); - break; - - case PROP_DURATION_MAX: - g_value_set_uint (value, hildon_time_editor_get_duration_max (time_editor)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -/** - * hildon_time_editor_new: - * - * This function creates a new time editor. - * - * Returns: pointer to a new #HildonTimeEditor widget - */ -GtkWidget* -hildon_time_editor_new (void) -{ - return GTK_WIDGET (g_object_new (HILDON_TYPE_TIME_EDITOR, NULL)); -} - -static void -hildon_time_editor_finalize (GObject *obj_self) -{ - HildonTimeEditorPrivate *priv = HILDON_TIME_EDITOR_GET_PRIVATE (obj_self); - g_assert (priv); - - if (priv->am_symbol) - g_free (priv->am_symbol); - - if (priv->pm_symbol) - g_free (priv->pm_symbol); - - if (priv->highlight_idle) - g_source_remove (priv->highlight_idle); - - if (G_OBJECT_CLASS (parent_class)->finalize) - G_OBJECT_CLASS (parent_class)->finalize (obj_self); -} - -/** - * hildon_time_editor_get_time_separators: - * @hm_sep_label: the label that will show the hour:minutes separator - * @ms_sep_label: the label that will show the minutes:seconds separator - * - * Gets hour-minute separator and minute-second separator from current - * locale and sets then to the labels we set as parameters. Both - * parameters can be NULL if you just want to assing one separator. - * - */ -void -hildon_time_editor_get_time_separators (GtkLabel *hm_sep_label, - GtkLabel *ms_sep_label) -{ - gchar buffer[256]; - gchar *separator; - GDate locale_test_date; - gchar *iter, *endp = NULL; - - /* Get localized time string */ - g_date_set_dmy (&locale_test_date, 1, 2, 1970); - (void) g_date_strftime (buffer, sizeof (buffer), "%X", &locale_test_date); - - /* Find h-m separator */ - iter = buffer; - while (*iter && g_ascii_isdigit (*iter)) iter++; - /* Extract h-m separator*/ - endp = iter; - while (*endp && ! g_ascii_isdigit (*endp)) endp++; - - if (hm_sep_label != NULL) - { - separator = g_strndup (iter, endp - iter); - gtk_label_set_label (hm_sep_label, separator); - g_free (separator); - } - - if (ms_sep_label != NULL) - { - /* Find m-s separator */ - iter = endp; - while (*iter && g_ascii_isdigit (*iter)) iter++; - - /* Extract m-s separator*/ - endp = iter; - while (*endp && ! g_ascii_isdigit (*endp)) endp++; - separator = g_strndup (iter, endp - iter); - gtk_label_set_label (ms_sep_label, separator); - g_free (separator); - } -} - -/* Convert ticks to H:M:S. Ticks = seconds since 00:00:00. */ -static void -ticks_to_time (guint ticks, - guint *hours, - guint *minutes, - guint *seconds) -{ - guint left; - - *hours = ticks / 3600; - left = ticks % 3600; - *minutes = left / 60; - *seconds = left % 60; -} - -/** - * hildon_time_editor_set_ticks: - * @editor: the #HildonTimeEditor widget - * @ticks: the duration to set, in seconds - * - * Sets the current duration in seconds. This means seconds from - * midnight, if not in duration mode. In case of any errors, it tries - * to fix it. - */ - -void -hildon_time_editor_set_ticks (HildonTimeEditor *editor, - guint ticks) -{ - HildonTimeEditorPrivate *priv; - guint i, h, m, s; - gchar str[3]; - - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* Validate ticks. If it's too low or too high, set it to - min/max value for the current mode. */ - if (priv->duration_mode) - priv->ticks = CLAMP (ticks, priv->duration_min, priv->duration_max); - else { - /* Check that ticks value is valid. We only need to check that hours - don't exceed 23. */ - ticks_to_time (ticks, &h, &m, &s); - if (h > HOURS_MAX_24) - ticks = TICKS(HOURS_MAX_24, m, s); - - priv->ticks = ticks; - } - - /* Get the time in H:M:S. */ - ticks_to_time (priv->ticks, &h, &m, &s); - - if (!priv->clock_24h && ! priv->duration_mode) - { - /* Convert 24h H:M:S values to 12h mode, and update AM/PM state */ - convert_to_12h (&h, &priv->am); - } - - /* Set H:M:S values to entries. We do not want to invoke validation - callbacks (since they can cause new call to this function), so we - block signals while setting values. */ - for (i = 0; i < ENTRY_COUNT; i++) - { - g_signal_handlers_block_by_func(priv->entries[i], - (gpointer) hildon_time_editor_entry_changed, editor); - - g_signal_handlers_block_by_func(priv->entries[i], - (gpointer) hildon_time_editor_inserted_text, editor); - - g_signal_handlers_block_by_func(priv->entries[i], - (gpointer) hildon_time_editor_entry_focus_out, editor); - } - - g_snprintf (str, sizeof (str), "%02u", h); - gtk_entry_set_text (GTK_ENTRY (priv->entries[ENTRY_HOURS]), str); - - g_snprintf(str, sizeof (str), "%02u", m); - gtk_entry_set_text (GTK_ENTRY (priv->entries[ENTRY_MINS]), str); - - g_snprintf(str, sizeof (str), "%02u", s); - gtk_entry_set_text (GTK_ENTRY (priv->entries[ENTRY_SECS]), str); - - for (i = 0; i < ENTRY_COUNT; i++) - { - g_signal_handlers_unblock_by_func (priv->entries[i], - (gpointer) hildon_time_editor_entry_changed, editor); - - g_signal_handlers_unblock_by_func (priv->entries[i], - (gpointer) hildon_time_editor_inserted_text, editor); - - g_signal_handlers_unblock_by_func (priv->entries[i], - (gpointer) hildon_time_editor_entry_focus_out, editor); - } - - /* Update AM/PM label in case we're in 12h mode */ - gtk_label_set_label( GTK_LABEL (priv->ampm_label), - priv->am ? priv->am_symbol : priv->pm_symbol); - - g_object_notify (G_OBJECT (editor), "ticks"); -} - -static void -hildon_time_editor_set_to_current_time (HildonTimeEditor *editor) -{ - time_t now; - const struct tm *tm; - - now = time (NULL); - tm = localtime (&now); - - if (tm != NULL) - hildon_time_editor_set_time (editor, tm->tm_hour, tm->tm_min, tm->tm_sec); -} - -/** - * hildon_time_editor_get_ticks: - * @editor: the #HildonTimeEditor widget - * - * This function returns the current duration, in seconds. - * This means seconds from midnight, if not in duration mode. - * - * Returns: current duration in seconds - */ -guint -hildon_time_editor_get_ticks (HildonTimeEditor *editor) -{ - HildonTimeEditorPrivate *priv; - - g_return_val_if_fail (HILDON_IS_TIME_EDITOR (editor), 0); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE(editor); - g_assert (priv); - - return (priv->ticks); -} - -/** - * hildon_time_editor_set_show_seconds: - * @editor: the #HildonTimeEditor - * @show_seconds: enable or disable showing of seconds - * - * This function shows or hides the seconds field. - */ -void -hildon_time_editor_set_show_seconds (HildonTimeEditor *editor, - gboolean show_seconds) -{ - HildonTimeEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (show_seconds != priv->show_seconds) { - priv->show_seconds = show_seconds; - - /* show/hide seconds field and its ':' label if the value changed. */ - if (show_seconds) { - gtk_widget_show (priv->entries[ENTRY_SECS]); - gtk_widget_show (priv->sec_label); - } else { - gtk_widget_hide (priv->entries[ENTRY_SECS]); - gtk_widget_hide (priv->sec_label); - } - - g_object_notify (G_OBJECT (editor), "show_seconds"); - } -} - -/** - * hildon_time_editor_get_show_seconds: - * @editor: the #HildonTimeEditor widget - * - * This function returns a boolean indicating the visibility of - * seconds in the #HildonTimeEditor - * - * Returns: TRUE if the seconds are visible - */ -gboolean -hildon_time_editor_get_show_seconds (HildonTimeEditor *editor) -{ - HildonTimeEditorPrivate *priv; - - g_return_val_if_fail (HILDON_IS_TIME_EDITOR (editor), FALSE); - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - return (priv->show_seconds); -} - -/** - * hildon_time_editor_set_duration_mode: - * @editor: the #HildonTimeEditor - * @duration_mode: enable or disable duration editor mode - * - * This function sets the duration editor mode in which the maximum hours - * is 99. - */ -void -hildon_time_editor_set_duration_mode (HildonTimeEditor *editor, - gboolean duration_mode) -{ - HildonTimeEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (duration_mode != priv->duration_mode) { - priv->duration_mode = duration_mode; - - if (duration_mode) { - /* FIXME: Why do we reset the duration range here? - Would change API, so won't touch this for now. */ - hildon_time_editor_set_duration_range (editor, MIN_DURATION, MAX_DURATION); - /* There's no AM/PM label or time picker icon in duration mode. - Make sure they're hidden. */ - gtk_widget_hide (GTK_WIDGET (priv->ampm_label)); - gtk_widget_hide (GTK_WIDGET (priv->ampm_button)); - gtk_widget_hide (GTK_WIDGET (priv->iconbutton)); - /* Duration mode has seconds by default. */ - hildon_time_editor_set_show_seconds (editor, TRUE); - } else { - /* Make sure AM/PM label and time picker icons are visible if needed */ - if (! priv->clock_24h) - gtk_widget_show (GTK_WIDGET (priv->ampm_label)); - - gtk_widget_show (GTK_WIDGET (priv->ampm_button)); - gtk_widget_show (GTK_WIDGET (priv->iconbutton)); - - /* Reset the ticks to current time. Anything set in duration mode - * is bound to be invalid or useless in time mode. - */ - hildon_time_editor_set_to_current_time (editor); - } - - g_object_notify (G_OBJECT (editor), "duration_mode"); - } -} - -/** - * hildon_time_editor_get_duration_mode: - * @editor: the #HildonTimeEditor widget - * - * This function returns a boolean indicating whether the #HildonTimeEditor - * is in the duration mode. - * - * Returns: TRUE if the #HildonTimeEditor is in duration mode - */ -gboolean -hildon_time_editor_get_duration_mode (HildonTimeEditor *editor) -{ - HildonTimeEditorPrivate *priv; - - g_return_val_if_fail (HILDON_IS_TIME_EDITOR (editor), FALSE); - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - return (priv->duration_mode); -} - -/** - * hildon_time_editor_set_duration_min: - * @editor: the #HildonTimeEditor widget - * @duration_min: mimimum allowed duration - * - * Sets the minimum allowed duration for the duration mode. - * Note: Has no effect in time mode - */ -void -hildon_time_editor_set_duration_min (HildonTimeEditor *editor, - guint duration_min) -{ - HildonTimeEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - g_return_if_fail (duration_min >= MIN_DURATION); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (! priv->duration_mode ) - return; - - priv->duration_min = duration_min; - - /* Clamp the current value to the minimum if necessary */ - if (priv->ticks < duration_min) - { - hildon_time_editor_set_ticks (editor, duration_min); - } - - g_object_notify (G_OBJECT (editor), "duration_min"); -} - -/** - * hildon_time_editor_get_duration_min: - * @editor: the #HildonTimeEditor widget - * - * This function returns the smallest duration the #HildonTimeEditor - * allows in the duration mode. - * - * Returns: minimum allowed duration in seconds - */ -guint -hildon_time_editor_get_duration_min (HildonTimeEditor *editor) -{ - HildonTimeEditorPrivate *priv; - - g_return_val_if_fail (HILDON_IS_TIME_EDITOR (editor), 0); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if(! priv->duration_mode ) - return (0); - - return (priv->duration_min); -} - -/** - * hildon_time_editor_set_duration_max: - * @editor: the #HildonTimeEditor widget - * @duration_max: maximum allowed duration in seconds - * - * Sets the maximum allowed duration in seconds for the duration mode. - * Note: Has no effect in time mode - */ -void -hildon_time_editor_set_duration_max (HildonTimeEditor *editor, - guint duration_max) -{ - HildonTimeEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - g_return_if_fail (duration_max <= MAX_DURATION); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE(editor); - g_assert (priv); - - if (! priv->duration_mode) - return; - - priv->duration_max = duration_max; - - /* Clamp the current value to the maximum if necessary */ - if (priv->ticks > duration_max) - { - hildon_time_editor_set_ticks (editor, duration_max); - } - - g_object_notify (G_OBJECT (editor), "duration_max"); -} - -/** - * hildon_time_editor_get_duration_max: - * @editor: the #HildonTimeEditor widget - * - * This function returns the longest duration the #HildonTimeEditor - * allows in the duration mode. - * - * Returns: maximum allowed duration in seconds - */ -guint -hildon_time_editor_get_duration_max (HildonTimeEditor * editor) -{ - HildonTimeEditorPrivate *priv; - - g_return_val_if_fail (HILDON_IS_TIME_EDITOR (editor), 0); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (! priv->duration_mode) - return (0); - - return (priv->duration_max); -} - -/** - * hildon_time_editor_set_time: - * @editor: the #HildonTimeEditor widget - * @hours: hours - * @minutes: minutes - * @seconds: seconds - * - * This function sets the time on an existing time editor. If the - * time specified by the arguments is invalid, it's fixed. - * The time is assumed to be in 24h format. - */ -void -hildon_time_editor_set_time (HildonTimeEditor *editor, - guint hours, - guint minutes, - guint seconds) -{ - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - - hildon_time_editor_set_ticks (editor, TICKS(hours, minutes, seconds)); -} - -/** - * hildon_time_editor_get_time: - * @editor: the #HildonTimeEditor widget - * @hours: hours - * @minutes: minutes - * @seconds: seconds - * - * Gets the time of the #HildonTimeEditor widget. The time returned is - * always in 24h format. - */ -void -hildon_time_editor_get_time (HildonTimeEditor *editor, - guint *hours, - guint *minutes, - guint *seconds) -{ - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - - ticks_to_time (hildon_time_editor_get_ticks (editor), hours, minutes, seconds); -} - -/** - * hildon_time_editor_set_duration_range: - * @editor: the #HildonTimeEditor widget - * @min_seconds: minimum allowed time in seconds - * @max_seconds: maximum allowed time in seconds - * - * Sets the duration editor time range of the #HildonTimeEditor widget. - */ -void -hildon_time_editor_set_duration_range (HildonTimeEditor *editor, - guint min_seconds, - guint max_seconds) -{ - HildonTimeEditorPrivate *priv; - guint tmp; - - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* Swap values if reversed */ - if (min_seconds > max_seconds) - { - tmp = max_seconds; - max_seconds = min_seconds; - min_seconds = tmp; - } - - hildon_time_editor_set_duration_max (editor, max_seconds); - hildon_time_editor_set_duration_min (editor, min_seconds); - - if (priv->duration_mode) { - /* Set minimum allowed value for duration editor. - FIXME: Shouldn't it be changed only if it's not in range? - Would change API, so won't touch this for now. */ - hildon_time_editor_set_ticks (editor, min_seconds); - } -} - -/** - * hildon_time_editor_get_duration_range: - * @editor: the #HildonTimeEditor widget - * @min_seconds: pointer to guint - * @max_seconds: pointer to guint - * - * Gets the duration editor time range of the #HildonTimeEditor widget. - */ -void -hildon_time_editor_get_duration_range (HildonTimeEditor *editor, - guint *min_seconds, - guint *max_seconds) -{ - HildonTimeEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - *min_seconds = priv->duration_min; - *max_seconds = priv->duration_max; -} - -static gboolean -hildon_time_editor_check_locale (HildonTimeEditor *editor) -{ - HildonTimeEditorPrivate *priv; - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* Update time separator symbols */ - hildon_time_editor_get_time_separators (GTK_LABEL (priv->hm_label), GTK_LABEL (priv->sec_label)); - - /* Get AM/PM symbols. */ - priv->am_symbol = g_strdup (nl_langinfo (AM_STR)); - priv->pm_symbol = g_strdup (nl_langinfo (PM_STR)); - - if (priv->am_symbol[0] == '\0') - return TRUE; - else { - /* 12h clock mode. Check if AM/PM should be before or after time. - %p is the AM/PM string, so we assume that if the format string - begins with %p it's in the beginning, and in any other case it's - in the end (although that's not necessarily the case). */ - if (strncmp (nl_langinfo (T_FMT_AMPM), "%p", 2) == 0) - priv->ampm_pos_after = FALSE; - return FALSE; - } -} - -static gboolean -hildon_time_editor_entry_focus_in (GtkWidget *widget, - GdkEventFocus *event, - gpointer data) -{ - gdk_threads_add_idle ((GSourceFunc) hildon_time_editor_entry_select_all, - GTK_ENTRY (widget)); - - return FALSE; -} - -static gboolean -hildon_time_editor_time_error (HildonTimeEditor *editor, - HildonDateTimeError type) -{ - return TRUE; -} - -/* Returns negative if we didn't get value, - * and should stop further validation - */ -static gint -validated_conversion (HildonTimeEditorPrivate *priv, - GtkWidget *field, - gint min, - gint max, - gint def_value, - gboolean allow_intermediate, - guint *error_code, - GString *error_string) -{ - const gchar *text; - gchar *tail; - long value; - - text = gtk_entry_get_text (GTK_ENTRY (field)); - - if (text && text[0]) - { - /* Try to convert entry text to number */ - value = strtol (text, &tail, 10); - - /* Check if conversion succeeded */ - if ((tail[0] == 0) && !(text[0] == '-')) - { - if (value > max) { - g_string_printf (error_string, _("ckct_ib_maximum_value"), max); - priv->error_widget = field; - *error_code = MAX_VALUE; - return max; - } - - if (value < min && !allow_intermediate) { - g_string_printf (error_string, _("ckct_ib_minimum_value"), min); - priv->error_widget = field; - *error_code = MIN_VALUE; - return min; - } - - return value; - } - - /* We'll handle failed conversions soon */ - else - { - if ((tail[0] == '-') || (text[0] == '-')) - { - g_string_printf (error_string, _("ckct_ib_minimum_value"), min); - priv->error_widget = field; - *error_code = MIN_VALUE; - return min; - } - } - } - else if (allow_intermediate) - return -1; /* Empty field while user is still editing. No error, but - cannot validate either... */ - else /* Empty field: show error and set value to minimum allowed */ - { - g_string_printf (error_string, _("ckct_ib_set_a_value_within_range"), min, max); - priv->error_widget = field; - *error_code = WITHIN_RANGE; - return def_value; - } - - /* Empty field and not allowed intermediated OR failed conversion */ - g_string_printf (error_string, _("ckct_ib_set_a_value_within_range"), min, max); - priv->error_widget = field; - *error_code = WITHIN_RANGE; - return -1; -} - -static void -hildon_time_editor_real_validate (HildonTimeEditor *editor, - gboolean allow_intermediate, - GString *error_string) -{ - HildonTimeEditorPrivate *priv; - guint h, m, s, ticks; - guint error_code; - guint max_hours, min_hours, def_hours; - guint max_minutes, min_minutes, def_minutes; - guint max_seconds, min_seconds, def_seconds; - gboolean r; - - g_assert (HILDON_IS_TIME_EDITOR (editor)); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* Find limits for field based validation. */ - if (priv->duration_mode) - { - ticks_to_time (priv->duration_min, &min_hours, &min_minutes, &min_seconds); - ticks_to_time (priv->duration_max, &max_hours, &max_minutes, &max_seconds); - } else { - if (priv->clock_24h) { - max_hours = HOURS_MAX_24; - min_hours = HOURS_MIN_24; - } else { - max_hours = HOURS_MAX_12; - min_hours = HOURS_MIN_12; - } - } - - hildon_time_editor_get_time (editor, &def_hours, &def_minutes, &def_seconds); - - /* Get time components from fields and validate them... */ - if (priv->show_hours) { - h = validated_conversion (priv, priv->entries[ENTRY_HOURS], min_hours, max_hours, def_hours, - allow_intermediate, &error_code, error_string); - if (priv->error_widget == priv->entries[ENTRY_HOURS]) - g_signal_emit (editor, time_editor_signals [TIME_ERROR], 0, hour_errors[error_code], &r); - if ((gint) h < 0) return; - } - else h = 0; - m = validated_conversion (priv, priv->entries[ENTRY_MINS], MINUTES_MIN, MINUTES_MAX, def_minutes, - allow_intermediate, &error_code, error_string); - if (priv->error_widget == priv->entries[ENTRY_MINS]) - g_signal_emit (editor, time_editor_signals [TIME_ERROR], 0, min_errors[error_code], &r); - if ((gint) m < 0) return; - if (priv->show_seconds) { - s = validated_conversion (priv, priv->entries[ENTRY_SECS], SECONDS_MIN, SECONDS_MAX, def_seconds, - allow_intermediate, &error_code, error_string); - if (priv->error_widget == priv->entries[ENTRY_SECS]) - g_signal_emit (editor, time_editor_signals [TIME_ERROR], 0, sec_errors[error_code], &r); - if ((gint) s < 0) return; - } - else s = 0; - - /* Ok, we now do separate check that tick count is valid for duration mode */ - if (priv->duration_mode) - { - ticks = TICKS(h, m, s); - - if (ticks < priv->duration_min && !allow_intermediate) - { - g_string_printf (error_string, - _("ckct_ib_min_allowed_duration_hts"), - min_hours, min_minutes, min_seconds); - hildon_time_editor_set_ticks (editor, priv->duration_min); - priv->error_widget = priv->show_hours ? priv->entries[ENTRY_HOURS] : priv->entries[ENTRY_MINS]; - g_signal_emit (editor, time_editor_signals[TIME_ERROR], 0, HILDON_DATE_TIME_ERROR_MIN_DURATION, &r); - return; - } - else if (ticks > priv->duration_max) - { - g_string_printf (error_string, - _("ckct_ib_max_allowed_duration_hts"), - max_hours, max_minutes, max_seconds); - hildon_time_editor_set_ticks (editor, priv->duration_max); - priv->error_widget = priv->show_hours ? priv->entries[ENTRY_HOURS] : priv->entries[ENTRY_MINS]; - g_signal_emit (editor, time_editor_signals[TIME_ERROR], 0, HILDON_DATE_TIME_ERROR_MAX_DURATION, &r); - return; - } - } - else if (! priv->clock_24h) - convert_to_24h (&h, priv->am); - - /* The only case when we do not want to refresh the - time display, is when the user is editing a value - (unless the value was out of bounds and we have to fix it) */ - if (! allow_intermediate || priv->error_widget) - hildon_time_editor_set_time (editor, h, m, s); -} - -/* Setting text to entries causes entry to recompute itself - in idle callback, which remove selection. Because of this - we need to do selection in idle as well. */ -static gboolean -highlight_callback (gpointer data) -{ - HildonTimeEditorPrivate *priv; - GtkWidget *widget; - gint i; - - g_assert (HILDON_IS_TIME_EDITOR (data)); - priv = HILDON_TIME_EDITOR_GET_PRIVATE (data); - g_assert (priv); - - widget = priv->error_widget; - priv->error_widget = NULL; - - if (GTK_IS_WIDGET (widget) == FALSE) - goto Done; - - /* Avoid revalidation because it will issue the date_error signal - twice when there is an empty field. We must block the signal - for all the entries because we do not know where the focus - comes from */ - for (i = 0; i < ENTRY_COUNT; i++) - g_signal_handlers_block_by_func (priv->entries[i], - (gpointer) hildon_time_editor_entry_focus_out, data); - gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1); - gtk_widget_grab_focus (widget); - for (i = 0; i < ENTRY_COUNT; i++) - g_signal_handlers_unblock_by_func (priv->entries[i], - (gpointer) hildon_time_editor_entry_focus_out, data); - -Done: - priv->highlight_idle = 0; - - return FALSE; -} - -/* Update ticks from current H:M:S entries. If they're invalid, show an - infoprint and update the fields unless they're empty. */ -static void -hildon_time_editor_validate (HildonTimeEditor *editor, - gboolean allow_intermediate) -{ - HildonTimeEditorPrivate *priv; - GString *error_message; - - g_assert (HILDON_IS_TIME_EDITOR(editor)); - priv = HILDON_TIME_EDITOR_GET_PRIVATE(editor); - g_assert (priv); - - /* if there is already an error we do nothing until it will be managed by the idle */ - if (priv->highlight_idle == 0 && priv->skipper == FALSE) - { - priv->skipper = TRUE; - error_message = g_string_new (NULL); - hildon_time_editor_real_validate (editor, - allow_intermediate, error_message); - - if (priv->error_widget) - { - hildon_banner_show_information (priv->error_widget, NULL, - error_message->str); - - priv->highlight_idle = gdk_threads_add_idle (highlight_callback, editor); - } - - priv->skipper = FALSE; - g_string_free (error_message, TRUE); - } -} - -/* on inserted text, if entry has two digits, jumps to the next field. */ -static void -hildon_time_editor_inserted_text (GtkEditable *editable, - gchar *new_text, - gint new_text_length, - gint *position, - gpointer user_data) -{ - HildonTimeEditor *editor; - GtkEntry *entry; - gchar *value; - HildonTimeEditorPrivate *priv; - - entry = GTK_ENTRY (editable); - editor = HILDON_TIME_EDITOR (user_data); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* if there is already an error we don't have to do anything */ - if (! priv->error_widget) - { - value = (gchar *) gtk_entry_get_text (entry); - - if (strlen (value) == 2) - { - if (GTK_WIDGET (editable) == priv->entries[ENTRY_HOURS]) - { - /* We already checked the input in changed signal, but - * now we will re-check it again in focus-out we - * intermediate flag set to FALSE */ - gtk_widget_grab_focus (priv->entries[ENTRY_MINS]); - *position = -1; - } - else if (GTK_WIDGET (editable) == priv->entries[ENTRY_MINS] && - GTK_WIDGET_VISIBLE (priv->entries[ENTRY_SECS])) - { - /* See above */ - gtk_widget_grab_focus (priv->entries[ENTRY_SECS]); - *position = -1; - } - } - } -} - -static gboolean -hildon_time_editor_entry_focus_out (GtkWidget *widget, - GdkEventFocus *event, - gpointer data) -{ - g_assert (HILDON_IS_TIME_EDITOR (data)); - - /* Validate the given time and update ticks. */ - hildon_time_editor_validate (HILDON_TIME_EDITOR (data), FALSE); - - return FALSE; -} - -static gboolean -hildon_time_editor_ampm_clicked (GtkWidget *widget, - gpointer data) -{ - HildonTimeEditor *editor; - HildonTimeEditorPrivate *priv; - - g_assert (GTK_IS_WIDGET (widget)); - g_assert (HILDON_IS_TIME_EDITOR (data)); - - editor = HILDON_TIME_EDITOR (data); - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* First validate the given time and update ticks. */ - hildon_time_editor_validate (editor, FALSE); - - /* Apply the AM/PM change by moving the current time by 12 hours */ - if (priv->am) { - /* 00:00 .. 11:59 -> 12:00 .. 23:59 */ - hildon_time_editor_set_ticks (editor, priv->ticks + 12 * 3600); - } else { - /* 12:00 .. 23:59 -> 00:00 .. 11:59 */ - hildon_time_editor_set_ticks (editor, priv->ticks - 12 * 3600); - } - - return FALSE; -} - -static gboolean -hildon_time_editor_icon_clicked (GtkWidget *widget, - gpointer data) -{ - HildonTimeEditor *editor; - GtkWidget *picker; - GtkWidget *parent; - guint h, m, s, result; - HildonTimeEditorPrivate *priv; - - g_assert (HILDON_IS_TIME_EDITOR (data)); - - editor = HILDON_TIME_EDITOR (data); - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - /* icon is passive in duration editor mode */ - if (hildon_time_editor_get_duration_mode (editor)) - return FALSE; - - /* Validate and do not launch if broken */ - hildon_time_editor_validate (HILDON_TIME_EDITOR (data), FALSE); - if (priv->error_widget != NULL) - return FALSE; - - /* Launch HildonTimePicker dialog */ - parent = gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW); - picker = hildon_time_picker_new (GTK_WINDOW (parent)); - - hildon_time_editor_get_time (editor, &h, &m, &s); - hildon_time_picker_set_time (HILDON_TIME_PICKER (picker), h, m); - - result = gtk_dialog_run (GTK_DIALOG (picker)); - switch (result) { - - case GTK_RESPONSE_OK: - case GTK_RESPONSE_ACCEPT: - /* Use the selected time */ - hildon_time_picker_get_time (HILDON_TIME_PICKER (picker), &h, &m); - hildon_time_editor_set_time (editor, h, m, 0); - break; - - default: - break; - } - - gtk_widget_destroy (picker); - return FALSE; -} - -static void -hildon_time_editor_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - HildonTimeEditor *editor; - HildonTimeEditorPrivate *priv; - GtkRequisition req; - - editor = HILDON_TIME_EDITOR (widget); - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - - /* Get frame's size */ - gtk_widget_size_request (priv->frame, requisition); - - if (GTK_WIDGET_VISIBLE (priv->iconbutton)) - { - gtk_widget_size_request (priv->iconbutton, &req); - /* Reserve space for icon */ - requisition->width += req.width + ICON_PRESSED + - HILDON_MARGIN_DEFAULT; - } - - /* FIXME: It's evil to use hardcoded TIME_EDITOR_HEIGHT. For now we'll - want to force this since themes might have varying thickness values - which cause the height to change. */ - requisition->height = TIME_EDITOR_HEIGHT; -} - -static void -hildon_time_editor_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - HildonTimeEditorPrivate *priv = HILDON_TIME_EDITOR_GET_PRIVATE (widget); - GtkAllocation alloc; - GtkRequisition req, max_req; - gboolean rtl; - - g_assert (priv); - - rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL); - widget->allocation = *allocation; - gtk_widget_get_child_requisition (widget, &max_req); - - /* Center horizontally */ - alloc.x = allocation->x + MAX (allocation->width - max_req.width, 0) / 2; - /* Center vertically */ - alloc.y = allocation->y + MAX (allocation->height - max_req.height, 0) / 2; - - /* allocate frame */ - if (rtl) - gtk_widget_get_child_requisition (priv->iconbutton, &req); - else - gtk_widget_get_child_requisition (priv->frame, &req); - - alloc.width = req.width; - alloc.height = max_req.height; - if (rtl) - gtk_widget_size_allocate (priv->iconbutton, &alloc); - else - gtk_widget_size_allocate (priv->frame, &alloc); - - /* allocate icon */ - if (GTK_WIDGET_VISIBLE (priv->iconbutton)) { - if (rtl) - gtk_widget_get_child_requisition (priv->frame, &req); - else - gtk_widget_get_child_requisition (priv->iconbutton, &req); - - alloc.x += alloc.width + HILDON_MARGIN_DEFAULT; - alloc.width = req.width; - - if (rtl) - gtk_widget_size_allocate (priv->frame, &alloc); - else - gtk_widget_size_allocate (priv->iconbutton, &alloc); - } - - /* FIXME: ugly way to move labels up. They just don't seem move up - otherwise. This is likely because we force the editor to be - smaller than it otherwise would be. */ - alloc = priv->ampm_label->allocation; - alloc.y = allocation->y - 2; - alloc.height = max_req.height + 2; - gtk_widget_size_allocate (priv->ampm_label, &alloc); - - alloc = priv->hm_label->allocation; - alloc.y = allocation->y - 2; - alloc.height = max_req.height + 2; - gtk_widget_size_allocate (priv->hm_label, &alloc); - - alloc = priv->sec_label->allocation; - alloc.y = allocation->y - 2; - alloc.height = max_req.height + 2; - gtk_widget_size_allocate (priv->sec_label, &alloc); -} - -static gboolean -hildon_time_editor_focus (GtkWidget *widget, - GtkDirectionType direction) -{ - gboolean retval; - GtkDirectionType effective_direction; - - g_assert (HILDON_IS_TIME_EDITOR (widget)); - - retval = hildon_private_composite_focus (widget, direction, &effective_direction); - - if (retval == TRUE) - return GTK_WIDGET_CLASS (parent_class)->focus (widget, effective_direction); - else - return FALSE; -} - -static gboolean -hildon_time_editor_entry_keypress (GtkEntry *entry, - GdkEventKey *event, - gpointer data) -{ - switch (event->keyval) - { - case GDK_Return: - case GDK_ISO_Enter: - hildon_time_editor_icon_clicked (GTK_WIDGET (entry), data); - return TRUE; - default: - return FALSE; - } - - g_assert_not_reached (); -} - -static void -convert_to_12h (guint *h, - gboolean *am) -{ - g_assert (0 <= *h && *h < 24); - - /* 00:00 to 00:59 add 12 hours */ - /* 01:00 to 11:59 straight to am */ - /* 12:00 to 12:59 straight to pm */ - /* 13:00 to 23:59 subtract 12 hours */ - - if ( *h == 0 ) { *am = TRUE; *h += 12;} - else if ( 1 <= *h && *h < 12 ) { *am = TRUE; } - else if ( 12 <= *h && *h < 13 ) { *am = FALSE; } - else { *am = FALSE; *h -= 12;} -} - -static void -convert_to_24h (guint *h, - gboolean am) -{ - if (*h == 12 && am) /* 12 midnight - 12:59 AM subtract 12 hours */ - { - *h -= 12; - } - - else if (! am && 1 <= *h && *h < 12) /* 1:00 PM - 11:59 AM add 12 hours */ - { - *h += 12; - } -} - -/** - * hildon_time_editor_set_show_hours: - * @editor: The #HildonTimeEditor. - * @show_hours: Enable or disable showing of hours. - * - * This function shows or hides the hours field. - * - **/ -void -hildon_time_editor_set_show_hours (HildonTimeEditor *editor, - gboolean show_hours) -{ - HildonTimeEditorPrivate *priv; - - g_return_if_fail (HILDON_IS_TIME_EDITOR (editor)); - - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - if (show_hours != priv->show_hours) { - priv->show_hours = show_hours; - - /* show/hide hours field and its ':' label if the value changed. */ - if (show_hours) { - gtk_widget_show (priv->entries[ENTRY_HOURS]); - gtk_widget_show (priv->hm_label); - } else { - gtk_widget_hide (priv->entries[ENTRY_HOURS]); - gtk_widget_hide (priv->hm_label); - } - - g_object_notify (G_OBJECT (editor), "show_hours"); - } -} - -/** - * hildon_time_editor_get_show_hours: - * @editor: the @HildonTimeEditor widget. - * - * This function returns a boolean indicating the visibility of - * hours in the @HildonTimeEditor - * - * Return value: TRUE if hours are visible. - * - **/ -gboolean -hildon_time_editor_get_show_hours (HildonTimeEditor *editor) -{ - HildonTimeEditorPrivate *priv; - - g_return_val_if_fail (HILDON_IS_TIME_EDITOR (editor), FALSE); - priv = HILDON_TIME_EDITOR_GET_PRIVATE (editor); - g_assert (priv); - - return priv->show_hours; -} - -/* Idle callback */ -static gboolean -hildon_time_editor_entry_select_all (GtkWidget *widget) -{ - gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1); - return FALSE; -} diff --git a/hildon/hildon-time-editor.h b/hildon/hildon-time-editor.h deleted file mode 100644 index 110c977..0000000 --- a/hildon/hildon-time-editor.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_TIME_EDITOR_H__ -#define __HILDON_TIME_EDITOR_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define HILDON_TYPE_TIME_EDITOR \ - (hildon_time_editor_get_type()) - -#define HILDON_TIME_EDITOR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_TIME_EDITOR, HildonTimeEditor)) - -#define HILDON_TIME_EDITOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), HILDON_TYPE_TIME_EDITOR, \ - HildonTimeEditorClass)) - -#define HILDON_IS_TIME_EDITOR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_TIME_EDITOR)) - -#define HILDON_IS_TIME_EDITOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_TIME_EDITOR)) - -typedef enum -{ - HILDON_DATE_TIME_ERROR_NO_ERROR = -1, - HILDON_DATE_TIME_ERROR_MAX_HOURS, - HILDON_DATE_TIME_ERROR_MAX_MINS, - HILDON_DATE_TIME_ERROR_MAX_SECS, - HILDON_DATE_TIME_ERROR_MAX_DAY, - HILDON_DATE_TIME_ERROR_MAX_MONTH, - HILDON_DATE_TIME_ERROR_MAX_YEAR, - HILDON_DATE_TIME_ERROR_MIN_HOURS, - HILDON_DATE_TIME_ERROR_MIN_MINS, - HILDON_DATE_TIME_ERROR_MIN_SECS, - HILDON_DATE_TIME_ERROR_MIN_DAY, - HILDON_DATE_TIME_ERROR_MIN_MONTH, - HILDON_DATE_TIME_ERROR_MIN_YEAR, - HILDON_DATE_TIME_ERROR_EMPTY_HOURS, - HILDON_DATE_TIME_ERROR_EMPTY_MINS, - HILDON_DATE_TIME_ERROR_EMPTY_SECS, - HILDON_DATE_TIME_ERROR_EMPTY_DAY, - HILDON_DATE_TIME_ERROR_EMPTY_MONTH, - HILDON_DATE_TIME_ERROR_EMPTY_YEAR, - HILDON_DATE_TIME_ERROR_MIN_DURATION, - HILDON_DATE_TIME_ERROR_MAX_DURATION, - HILDON_DATE_TIME_ERROR_INVALID_CHAR, - HILDON_DATE_TIME_ERROR_INVALID_DATE, - HILDON_DATE_TIME_ERROR_INVALID_TIME -} HildonDateTimeError; - -typedef struct _HildonTimeEditor HildonTimeEditor; - -typedef struct _HildonTimeEditorClass HildonTimeEditorClass; - -struct _HildonTimeEditor -{ - GtkContainer parent; -}; - -struct _HildonTimeEditorClass -{ - GtkContainerClass parent_class; - - gboolean (*time_error) (HildonTimeEditor *editor, - HildonDateTimeError type); -}; - -GType G_GNUC_CONST -hildon_time_editor_get_type (void); - -GtkWidget* -hildon_time_editor_new (void); - -void -hildon_time_editor_set_time (HildonTimeEditor *editor, - guint hours, - guint minutes, - guint seconds); - -void -hildon_time_editor_get_time (HildonTimeEditor *editor, - guint *hours, - guint *minutes, - guint *seconds); - -void -hildon_time_editor_set_duration_range (HildonTimeEditor *editor, - guint min_seconds, - guint max_seconds); - -void -hildon_time_editor_get_duration_range (HildonTimeEditor *editor, - guint *min_seconds, - guint *max_seconds); - -void -hildon_time_editor_set_ticks (HildonTimeEditor *editor, - guint ticks); - -guint -hildon_time_editor_get_ticks (HildonTimeEditor *editor); - -void -hildon_time_editor_set_show_seconds (HildonTimeEditor *editor, - gboolean show_seconds); - -gboolean -hildon_time_editor_get_show_seconds (HildonTimeEditor *editor); - -void -hildon_time_editor_set_show_hours (HildonTimeEditor *editor, - gboolean show_hours); - -gboolean -hildon_time_editor_get_show_hours (HildonTimeEditor *editor); - -void -hildon_time_editor_set_duration_mode (HildonTimeEditor *editor, - gboolean duration_mode); - -gboolean -hildon_time_editor_get_duration_mode (HildonTimeEditor *editor); - -void -hildon_time_editor_set_duration_min (HildonTimeEditor *editor, - guint duration_min); - -guint -hildon_time_editor_get_duration_min (HildonTimeEditor *editor); - -void -hildon_time_editor_set_duration_max (HildonTimeEditor *editor, - guint duration_max); - -guint -hildon_time_editor_get_duration_max (HildonTimeEditor *editor); - -void -hildon_time_editor_get_time_separators (GtkLabel *hm_sep_label, - GtkLabel *ms_sep_label); - -G_END_DECLS - -#endif /* __HILDON_TIME_EDITOR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-time-picker-private.h b/hildon/hildon-time-picker-private.h deleted file mode 100644 index af57d8c..0000000 --- a/hildon/hildon-time-picker-private.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_TIME_PICKER_PRIVATE_H__ -#define __HILDON_TIME_PICKER_PRIVATE_H__ - -G_BEGIN_DECLS - -typedef struct _HildonTimePickerPrivate HildonTimePickerPrivate; - -#define HILDON_TIME_PICKER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_TIME_PICKER, HildonTimePickerPrivate)) - -enum -{ - WIDGET_GROUP_HOURS, - WIDGET_GROUP_10_MINUTES, - WIDGET_GROUP_1_MINUTES, - WIDGET_GROUP_AMPM, - - WIDGET_GROUP_COUNT -}; - -enum -{ - BUTTON_UP, - BUTTON_DOWN, - - BUTTON_COUNT -}; - -typedef struct -{ - GtkWidget *frame; - GtkWidget *eventbox; - GtkLabel *label; - - /* buttons are used for hours and minutes, but not for am/pm */ - GtkWidget *buttons[BUTTON_COUNT]; - -} HildonTimePickerWidgetGroup; - -struct _HildonTimePickerPrivate -{ - HildonTimePickerWidgetGroup widgets[WIDGET_GROUP_COUNT]; - - gchar *am_symbol; - gchar *pm_symbol; - - guint minutes; /* time in minutes since midnight */ - gint mul; /* for key repeat handling */ - guint timer_id; - - guint show_ampm : 1; /* 12 hour clock, show AM/PM */ - guint ampm_left : 1; - guint button_press : 1; - guint start_key_repeat : 1; -}; - -G_END_DECLS - -#endif /* __HILDON_TIME_PICKER_PRIVATE_H__ */ diff --git a/hildon/hildon-time-picker.c b/hildon/hildon-time-picker.c deleted file mode 100644 index 237d9c3..0000000 --- a/hildon/hildon-time-picker.c +++ /dev/null @@ -1,1012 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-time-picker - * @short_description: A dialog popup widget which lets the user set the time. - * @see_also: #HildonTimeEditor - * - * #HildonTimePicker is a dialog popup widget which lets the user set the time, - * using up/down arrows on hours and minutes. There are two arrows for minutes, - * so that minutes can be added also in 10 min increments.This widget is mainly - * used as a part of #HildonTimeEditor implementation. - * - * <note> - * <para> - * #HildonTimePicker has been deprecated since Hildon 2.2 and should not - * be used in newly written code. See - * <link linkend="hildon-migrating-time-widgets">Migrating Time Widgets</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <title>HildonTimePicker example</title> - * <programlisting> - * <!-- --> - * parent = gtk_widget_get_ancestor (GTK_WIDGET (editor), GTK_TYPE_WINDOW); - * picker = hildon_time_picker_new (GTK_WINDOW (parent)); - * <!-- --> - * hildon_time_editor_get_time (editor, &h, &m, &s); - * hildon_time_picker_set_time( HILDON_TIME_PICKER( picker ), h, m ); - * <!-- --> - * result = gtk_dialog_run (GTK_DIALOG (picker)); - * switch (result) - * { - * case GTK_RESPONSE_OK: - * case GTK_RESPONSE_ACCEPT: - * hildon_time_picker_get_time(HILDON_TIME_PICKER (picker), &h, &m ); - * foo_set_time(h,m); - * break; - * default: - * break; - * } - * <!-- --> - * gtk_widget_destroy( picker ); - * <!-- --> - * </programlisting> - * </example> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <time.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <langinfo.h> -#include <libintl.h> -#include <gtk/gtk.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-time-picker.h" -#include "hildon-defines.h" -#include "hildon-stock.h" -#include "hildon-time-picker-private.h" -#include "hildon-time-editor.h" - -#define DEFAULT_HOURS 1 - -#define DEFAULT_MINUTES 1 - -#define DEFAULT_ARROW_WIDTH 26 - -#define DEFAULT_ARROW_HEIGHT 26 - -#define MINS_IN_1H (60) - -#define MINS_IN_24H (MINS_IN_1H * 24) - -#define MINS_IN_12H (MINS_IN_1H * 12) - -#define HILDON_TIME_PICKER_LABEL_X_PADDING 0 - -#define HILDON_TIME_PICKER_LABEL_Y_PADDING 1 - -static void -hildon_time_picker_class_init (HildonTimePickerClass *klass); - -static void -hildon_time_picker_init (HildonTimePicker *picker); - -static gboolean -hildon_time_picker_key_repeat_timeout (gpointer tpicker); - -static void -hildon_time_picker_change_time (HildonTimePicker *picker, - guint minutes); - -static gboolean -hildon_time_picker_ampm_release (GtkWidget *widget, - GdkEvent *event, - HildonTimePicker *picker); - -static gboolean -hildon_time_picker_arrow_press (GtkWidget *widget, - GdkEvent *event, - HildonTimePicker *picker); - -static gboolean -hildon_time_picker_arrow_release (GtkWidget *widget, - GdkEvent *event, - HildonTimePicker *picker); - -static void -hildon_time_picker_finalize (GObject *object); - -static void -hildon_time_picker_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void -hildon_time_picker_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); - -static gboolean -hildon_time_picker_event_box_focus_in (GtkWidget *widget, - GdkEvent *event, - gpointer unused); - -static gboolean -hildon_time_picker_event_box_focus_out (GtkWidget *widget, - GdkEvent *event, - gpointer unused); - -static gboolean -hildon_time_picker_event_box_key_press (GtkWidget *widget, - GdkEventKey *event, - HildonTimePicker *picker); - -static gboolean -hildon_time_picker_event_box_key_release (GtkWidget *widget, - GdkEventKey *event, - HildonTimePicker *picker); - -static gboolean -hildon_time_picker_event_box_button_press (GtkWidget *widget, - GdkEventKey *event, - gpointer unused); - -static void -hildon_time_picker_realize (GtkWidget *widget); - -static void -hildon_time_picker_style_set (GtkWidget *widget, - GtkStyle *previous_style); - -static void -frame_size_request (GtkWidget *widget, - GtkRequisition *requistion); - -static GtkDialogClass* parent_class; - -enum -{ - PROP_0, - PROP_MINUTES -}; - -static const gint button_multipliers[WIDGET_GROUP_COUNT][2] = -{ - { MINS_IN_1H, -MINS_IN_1H }, - { 10, -10 }, - { 1, -1 }, - { 0, 0 } -}; - -/** - * hildon_time_picker_get_type: - * - * Returns the type of HildonTimePicker. - * - * Returns: HildonTimePicker type - */ -GType G_GNUC_CONST -hildon_time_picker_get_type (void) -{ - static GType picker_type = 0; - - if( !picker_type ) - { - static const GTypeInfo picker_info = - { - sizeof (HildonTimePickerClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc)hildon_time_picker_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonTimePicker), - 0, /* n_preallocs */ - (GInstanceInitFunc)hildon_time_picker_init, - }; - picker_type = g_type_register_static( GTK_TYPE_DIALOG, "HildonTimePicker", - &picker_info, 0 ); - } - return picker_type; -} - - -static void -hildon_time_picker_class_init (HildonTimePickerClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - parent_class = g_type_class_peek_parent (klass); - - gobject_class->finalize = hildon_time_picker_finalize; - gobject_class->get_property = hildon_time_picker_get_property; - gobject_class->set_property = hildon_time_picker_set_property; - widget_class->realize = hildon_time_picker_realize; - widget_class->style_set = hildon_time_picker_style_set; - - /** - * HildonTimePicker:minutes: - * - * Currently selected time in minutes since midnight. - */ - g_object_class_install_property (gobject_class, PROP_MINUTES, - g_param_spec_uint ("minutes", - "Current minutes", - "The selected time in minutes " - "since midnight", - 0, MINS_IN_24H, 0, - G_PARAM_READABLE | G_PARAM_WRITABLE) ); - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_uint ("arrow-width", - "Arrow width", - "Increase/decrease arrows width.", - 0, G_MAXUINT, - DEFAULT_ARROW_WIDTH, - G_PARAM_READABLE) ); - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_uint ("arrow-height", - "Arrow height", - "Increase/decrease arrows height.", - 0, G_MAXUINT, - DEFAULT_ARROW_HEIGHT, - G_PARAM_READABLE) ); - - g_type_class_add_private (klass, sizeof (HildonTimePickerPrivate)); -} - -/* Okay, this is really bad. We make the requisition of the frames a bit larger - * so that it doesn't "change" when digits are changed (see #37489). It's a - * really bad solution to a problem, but the whole layout of the time picker is - * on crack anyways */ -static void -frame_size_request (GtkWidget *widget, - GtkRequisition *requistion) -{ - int framed = requistion->width / 10; - requistion->width = (framed + 1) * 10; -} - -static void -hildon_time_picker_init (HildonTimePicker *picker) -{ - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker); - gint widget_group_table_column_pos[WIDGET_GROUP_COUNT]; - GtkDialog *dialog = GTK_DIALOG (picker); - GtkTable *table = NULL; - GtkWidget *maintocenter, *colon_label; - const struct tm *local = NULL; - time_t stamp; - gint i = 0; - - g_assert (priv); - - widget_group_table_column_pos[WIDGET_GROUP_HOURS] = 1; - widget_group_table_column_pos[WIDGET_GROUP_10_MINUTES] = 3; - widget_group_table_column_pos[WIDGET_GROUP_1_MINUTES] = 4; - widget_group_table_column_pos[WIDGET_GROUP_AMPM] = 5; - - /* Get AM/PM strings from locale. If they're set, the time is wanted - in 12 hour mode. */ - priv->am_symbol = g_strdup (nl_langinfo (AM_STR)); - priv->pm_symbol = g_strdup (nl_langinfo (PM_STR)); - - priv->show_ampm = priv->am_symbol[0] != '\0'; - if (priv->show_ampm) - { - /* Check if AM/PM should be before or after time. - %p is the AM/PM string, so we assume that if the format string - begins with %p it's in the beginning, and in any other case it's - in the end (although that's not necessarily the case). */ - if (strncmp (nl_langinfo (T_FMT_AMPM), "%p", 2) == 0) - { - /* Before time. Update column position. */ - priv->ampm_left = TRUE; - widget_group_table_column_pos[WIDGET_GROUP_AMPM] = 0; - } - } - - gtk_widget_push_composite_child (); - - /* Pack all our internal widgets into a table */ - table = GTK_TABLE (gtk_table_new (3, 6, FALSE)); - - /* Put everything centered into window */ - maintocenter = gtk_alignment_new (0.5, 0, 0, 0); - - /* Create our internal widgets */ - for (i = 0; i < WIDGET_GROUP_COUNT; i++) - { - HildonTimePickerWidgetGroup *group = &priv->widgets[i]; - gint table_column = widget_group_table_column_pos[i]; - - /* Create frame and attach to table. With AM/PM label we're attaching - it later. */ - group->frame = gtk_frame_new (NULL); - if (i != WIDGET_GROUP_AMPM) - { - gtk_table_attach (table, group->frame, table_column, table_column + 1, - 1, 2, GTK_EXPAND, GTK_EXPAND, 0, 0); - - - } - /* FIXME: is it needed to force it to 0 here? */ - gtk_container_set_border_width (GTK_CONTAINER(group->frame), 0); - - /* Create eventbox inside frame */ - group->eventbox = gtk_event_box_new (); - gtk_container_add (GTK_CONTAINER (group->frame), group->eventbox); - - g_object_set (group->eventbox, "can-focus", TRUE, NULL); - gtk_widget_set_events (group->eventbox, - GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_PRESS_MASK); - - /* Connect signals to eventbox */ - g_signal_connect (group->eventbox, "key-release-event", - G_CALLBACK (hildon_time_picker_event_box_key_release), - picker); - g_signal_connect (group->eventbox, "key-press-event", - G_CALLBACK (hildon_time_picker_event_box_key_press), - picker); - g_signal_connect (group->eventbox, "focus-in-event", - G_CALLBACK (hildon_time_picker_event_box_focus_in), - picker); - g_signal_connect (group->eventbox, "focus-out-event", - G_CALLBACK (hildon_time_picker_event_box_focus_out), - picker); - g_signal_connect (group->eventbox, "button-press-event", - G_CALLBACK (hildon_time_picker_event_box_button_press), - picker); - - /* Create label inside eventbox */ - group->label = GTK_LABEL (gtk_label_new (NULL)); - g_signal_connect (group->frame, "size-request", - G_CALLBACK (frame_size_request), - NULL); - gtk_misc_set_alignment (GTK_MISC (group->label), 0.5, 0.5); - gtk_container_add (GTK_CONTAINER (group->eventbox), GTK_WIDGET (group->label)); - - if (i != WIDGET_GROUP_AMPM) - { - gint button; - - /* Add some padding to hour and minute labels, and make them bigger */ - gtk_misc_set_padding(GTK_MISC (group->label), - HILDON_TIME_PICKER_LABEL_X_PADDING, - HILDON_TIME_PICKER_LABEL_Y_PADDING); - - gtk_widget_set_name (GTK_WIDGET(group->label), "osso-LargeFont"); - - /* Create up and down buttons for hours and mins */ - for (button = 0; button < BUTTON_COUNT; button++) - { - gint table_row = button == BUTTON_UP ? 0 : 2; - - group->buttons[button] = gtk_button_new (); - gtk_table_attach (table, group->buttons[button], - table_column, table_column + 1, - table_row, table_row + 1, - GTK_SHRINK, GTK_SHRINK, 0, 0); - g_object_set (group->buttons[button], "can-focus", FALSE, NULL); - - /* Connect signals */ - g_signal_connect(group->buttons[button], "button-press-event", - G_CALLBACK (hildon_time_picker_arrow_press), picker); - g_signal_connect(group->buttons[button], "button-release-event", - G_CALLBACK (hildon_time_picker_arrow_release), picker); - } - - gtk_widget_set_name (group->buttons[BUTTON_UP], - "hildon-time-picker-up"); - gtk_widget_set_name (group->buttons[BUTTON_DOWN], - "hildon-time-picker-down"); - } - } - - /* Label between hour and minutes */ - colon_label = gtk_label_new (NULL); - hildon_time_editor_get_time_separators (GTK_LABEL(colon_label), NULL); - - gtk_table_attach (table, colon_label, 2, 3, 1, 2, - GTK_SHRINK, GTK_SHRINK, 6, 0); /* FIXME: magic */ - gtk_widget_set_name (colon_label, "osso-LargeFont" ); - - priv->minutes = 0; - priv->mul = 0; - priv->start_key_repeat = FALSE; - priv->timer_id = 0; - priv->button_press = FALSE; - - gtk_table_set_row_spacing (table, 0, 6); - gtk_table_set_row_spacing (table, 1, 6); - - if (priv->show_ampm) - { - gint table_column = widget_group_table_column_pos[WIDGET_GROUP_AMPM]; - GtkWidget *ampmtotop = NULL; - - /* Show the AM/PM label centered vertically */ - ampmtotop = gtk_alignment_new (0, 0.5, 0, 0); - gtk_table_attach (table, ampmtotop, table_column, table_column + 1, - 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0); - gtk_container_add (GTK_CONTAINER (ampmtotop), - priv->widgets[WIDGET_GROUP_AMPM].frame); - - if (table_column != 0) - gtk_table_set_col_spacing (table, table_column - 1, 9); - - /* Connect AM/PM signal handlers */ - g_signal_connect (priv->widgets[WIDGET_GROUP_AMPM].eventbox, - "button-release-event", - G_CALLBACK(hildon_time_picker_ampm_release), picker); - } - - gtk_widget_pop_composite_child (); - - /* This dialog isn't modal */ - gtk_window_set_modal (GTK_WINDOW (dialog), FALSE); - /* And final dialog packing */ - gtk_dialog_set_has_separator (dialog, FALSE); - gtk_dialog_add_button (dialog, HILDON_STOCK_DONE, GTK_RESPONSE_OK); - - gtk_container_add (GTK_CONTAINER (maintocenter), GTK_WIDGET(table)); - gtk_box_pack_start (GTK_BOX (dialog->vbox), maintocenter, TRUE, FALSE, 0); - - /* Set default time to current time */ - stamp = time (NULL); - local = localtime (&stamp); - hildon_time_picker_set_time (picker, local->tm_hour, local->tm_min); - - gtk_widget_show_all (maintocenter); -} - -static void -hildon_time_picker_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonTimePicker *picker = HILDON_TIME_PICKER (object); - - switch (param_id) - { - - case PROP_MINUTES: - hildon_time_picker_change_time (picker, g_value_get_uint(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -hildon_time_picker_finalize (GObject *object) -{ - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (object); - - g_assert (priv); - - /* Make sure the timer is stopped */ - if (priv->timer_id) - g_source_remove(priv->timer_id); - - g_free(priv->am_symbol); - g_free(priv->pm_symbol); - - if (G_OBJECT_CLASS(parent_class)->finalize) - G_OBJECT_CLASS(parent_class)->finalize(object); -} - -static void -hildon_time_picker_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (object); - g_assert (priv); - - switch( param_id ) - { - case PROP_MINUTES: - g_value_set_uint (value, priv->minutes); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -hildon_time_picker_realize (GtkWidget *widget) -{ - GTK_WIDGET_CLASS (parent_class)->realize(widget); - - /* We only want the border for the dialog. */ - gdk_window_set_decorations (widget->window, GDK_DECOR_BORDER); -} - -static void -hildon_time_picker_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - guint width, height; - gint i, button; - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (widget); - g_assert (priv); - - GTK_WIDGET_CLASS (parent_class)->style_set(widget, previous_style); - - /* Update hour/minute up/down buttons sizes from style properties */ - gtk_widget_style_get (widget, - "arrow-width", &width, - "arrow-height", &height, NULL); - - for (i = 0; i < WIDGET_GROUP_COUNT; i++) - { - if (priv->widgets[i].buttons[0] != NULL) - { - for (button = 0; button < BUTTON_COUNT; button++) - { - gtk_widget_set_size_request (priv->widgets[i].buttons[button], width, height); - } - } - } -} - -/* - * Clicked hour/minute field. Move focus to it. - */ -static gboolean -hildon_time_picker_event_box_button_press (GtkWidget *widget, - GdkEventKey *event, - gpointer unused) -{ - gtk_widget_grab_focus (widget); - return FALSE; -} - -/* - * Clicked AM/PM label. Move focus to it and move the time by 12 hours. - */ -static gboolean -hildon_time_picker_ampm_release (GtkWidget *widget, - GdkEvent *event, - HildonTimePicker *picker) -{ - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - gtk_widget_grab_focus (widget); - hildon_time_picker_change_time (picker, priv->minutes > MINS_IN_12H ? - priv->minutes - MINS_IN_12H : - priv->minutes + MINS_IN_12H); - - return FALSE; -} - -static gboolean -hildon_time_picker_arrow_press (GtkWidget *widget, - GdkEvent *event, - HildonTimePicker *picker) -{ - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker); - gint i, button; - gint newval = 0; - gint key_repeat = 0; - - /* Make sure we don't add repeat timer twice. Normally it shouldn't - happen but WM can cause button release to be lost. */ - if (priv->button_press ) - return FALSE; - - priv->start_key_repeat = priv->button_press = TRUE; - - /* Find the widget which was clicked */ - priv->mul = 0; - for (i = 0; i < WIDGET_GROUP_COUNT; i++) - { - for (button = 0; button < BUTTON_COUNT; button++) - { - if (priv->widgets[i].buttons[button] == widget) - { - /* Update multiplier and move the focus to the clicked field */ - priv->mul = button_multipliers[i][button]; - gtk_widget_grab_focus (priv->widgets[i].eventbox); - break; - } - } - } - g_assert (priv->mul != 0); - - /* Change the time now, wrapping if needed. */ - newval = priv->minutes + priv->mul; - if( newval < 0 ) - newval += MINS_IN_24H; - - hildon_time_picker_change_time (picker, newval); - - /* Get button press repeater timeout from settings (in milliseconds) */ - g_object_get (gtk_widget_get_settings (widget), - "gtk-timeout-repeat", &key_repeat, NULL); - - key_repeat *= 8; - - /* Keep changing the time as long as button is being pressed. - The first repeat takes 3 times longer to start than the rest. */ - - priv->timer_id = gdk_threads_add_timeout (key_repeat * 3, - hildon_time_picker_key_repeat_timeout, - picker); - - return FALSE; -} - -static gboolean -hildon_time_picker_arrow_release (GtkWidget *widget, - GdkEvent *event, - HildonTimePicker *picker) -{ - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - if (priv->timer_id) - { - /* Stop repeat timer */ - g_source_remove (priv->timer_id); - priv->timer_id = 0; - } - - priv->button_press = FALSE; - return FALSE; -} - -static gboolean -hildon_time_picker_event_box_focus_in (GtkWidget *widget, - GdkEvent *event, - gpointer unused) -{ - /* Draw the widget in selected state so focus shows clearly. */ - gtk_widget_set_state (widget, GTK_STATE_SELECTED); - return FALSE; -} - -static gboolean -hildon_time_picker_event_box_focus_out (GtkWidget *widget, - GdkEvent *event, - gpointer unused) -{ - /* Draw the widget in normal state */ - gtk_widget_set_state( widget, GTK_STATE_NORMAL ); - return FALSE; -} - -static gint -hildon_time_picker_lookup_eventbox_group (HildonTimePicker *picker, - GtkWidget *widget) -{ - gint i; - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker); - - g_assert (priv); - - for (i = 0; i < WIDGET_GROUP_COUNT; i++) - { - if (priv->widgets[i].eventbox == widget) - return i; - } - return -1; -} - -static gboolean -hildon_time_picker_event_box_key_press (GtkWidget *widget, - GdkEventKey *event, - HildonTimePicker *picker) -{ - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker); - HildonTimePickerWidgetGroup *group; - gint group_idx; - - g_assert (priv); - - /* If mouse button is already being pressed, ignore this keypress */ - if (priv->timer_id ) - return TRUE; - - group_idx = hildon_time_picker_lookup_eventbox_group (picker, widget); - group = group_idx < 0 ? NULL : &priv->widgets[group_idx]; - - /* Handle keypresses in hour/minute/AMPM fields */ - switch (event->keyval) - { - case GDK_Up: - case GDK_Down: - if (group != NULL) - { - gint button = event->keyval == GDK_Up ? BUTTON_UP : BUTTON_DOWN; - - if (group->buttons[button] != NULL) - { - /* Fake a button up/down press */ - hildon_time_picker_arrow_press (group->buttons[button], NULL, picker); - gtk_widget_set_state (group->buttons[button], GTK_STATE_SELECTED); - } - else - { - /* Fake a AM/PM button release */ - g_assert (group_idx == WIDGET_GROUP_AMPM); - hildon_time_picker_ampm_release (group->eventbox, NULL, picker); - } - } - return TRUE; - - case GDK_Left: - /* If we're in leftmost field, stop this keypress signal. - Otherwise let the default key handler move focus to field in left. */ - if (priv->show_ampm && priv->ampm_left) - { - /* AM/PM is the leftmost field */ - if (group_idx == WIDGET_GROUP_AMPM) - return TRUE; - } - else - { - /* Hours is the leftmost field */ - if (group_idx == WIDGET_GROUP_HOURS) - return TRUE; - } - break; - - case GDK_Right: - /* If we're in rightmost field, stop this keypress signal. - Otherwise let the default key handler move focus to field in right. */ - if (priv->show_ampm && !priv->ampm_left) - { - /* AM/PM is the rightmost field */ - if (group_idx == WIDGET_GROUP_AMPM) - return TRUE; - } - else - { - /* 1-minutes is the leftmost field */ - if (group_idx == WIDGET_GROUP_1_MINUTES) - return TRUE; - } - break; - - case GDK_Escape: - gtk_dialog_response (GTK_DIALOG (picker), GTK_RESPONSE_CANCEL); - return TRUE; - - case GDK_Return: - gtk_dialog_response (GTK_DIALOG (picker), GTK_RESPONSE_OK); - return TRUE; - } - - return FALSE; -} - -static gboolean -hildon_time_picker_event_box_key_release (GtkWidget *widget, - GdkEventKey *event, - HildonTimePicker *picker) -{ - HildonTimePickerWidgetGroup *group; - gint group_idx; - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker); - - g_assert (priv); - - /* Fake a button release if in key-press handler we faked a button press. */ - switch( event->keyval ) - { - case GDK_Up: - case GDK_Down: - group_idx = hildon_time_picker_lookup_eventbox_group (picker, widget); - if (group_idx >= 0) - { - gint button = event->keyval == GDK_Up ? BUTTON_UP : BUTTON_DOWN; - - group = &priv->widgets[group_idx]; - if (group->buttons[button] != NULL) - { - /* Fake a button up/down press */ - gtk_widget_set_state (group->buttons[button], GTK_STATE_NORMAL); - hildon_time_picker_arrow_release (group->buttons[button], NULL, picker); - } - } - break; - } - return FALSE; -} - -/* Button up/down is being pressed. Update the time. */ -static gboolean -hildon_time_picker_key_repeat_timeout (gpointer tpicker) -{ - HildonTimePicker *picker; - HildonTimePickerPrivate *priv = NULL; - gint newval = 0; - gint key_repeat = 0; - - picker = HILDON_TIME_PICKER(tpicker); - g_assert(picker != NULL); - - priv = HILDON_TIME_PICKER_GET_PRIVATE (tpicker); - g_assert (priv); - - /* Change the time, wrapping if needed */ - newval = priv->minutes + priv->mul; - if (newval < 0) - newval += MINS_IN_24H; - - hildon_time_picker_change_time (picker, newval); - - if (priv->start_key_repeat) - { - /* Get button press repeater timeout from settings (in milliseconds) */ - g_object_get (gtk_widget_get_settings ((GtkWidget *) tpicker), - "gtk-timeout-repeat", &key_repeat, NULL); - - key_repeat *= 8; - - /* This is the first repeat. Shorten the timeout to key_repeat - (instead of the first time's 3*key_repeat) */ - priv->timer_id = gdk_threads_add_timeout (key_repeat, - hildon_time_picker_key_repeat_timeout, - picker); - priv->start_key_repeat = FALSE; - - return FALSE; - } - - return TRUE; -} - -static void -hildon_time_picker_change_time (HildonTimePicker *picker, - guint minutes) -{ - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker); - - gchar str[3] = "00"; - guint hours = 0; - gboolean ampm = TRUE; - - g_assert (priv); - - /* If the minutes isn't in valid range, wrap them. */ - minutes %= MINS_IN_24H; - - if (priv->minutes == minutes) - return; - - /* Minutes changed. Update widgets to show the new time. */ - priv->minutes = minutes; - - if (priv->show_ampm) - { - /* am < 12:00 <= pm */ - ampm = !((guint)(minutes / MINS_IN_12H)); - /* 12:00 - 23:59 -> 00:00 - 11:59 */ - minutes %= MINS_IN_12H; - if (minutes < MINS_IN_1H ) - /* 00:mm is always shown as 12:mm */ - minutes += MINS_IN_12H; - - /* Update the AM/PM label */ - gtk_label_set_text (priv->widgets[WIDGET_GROUP_AMPM].label, - ampm ? priv->am_symbol : priv->pm_symbol); - } - - /* Update hour and minute fields */ - hours = minutes / MINS_IN_1H; - minutes %= MINS_IN_1H; - - snprintf(str, sizeof (str), "%02d", hours); - gtk_label_set_text (priv->widgets[WIDGET_GROUP_HOURS].label, str); - - snprintf(str, sizeof (str), "%d", minutes / 10); - gtk_label_set_text (priv->widgets[WIDGET_GROUP_10_MINUTES].label, str); - - snprintf(str, sizeof (str), "%d", minutes % 10); - gtk_label_set_text(priv->widgets[WIDGET_GROUP_1_MINUTES].label, str); - - g_object_notify (G_OBJECT(picker), "minutes"); -} - -/** - * hildon_time_picker_new: - * @parent: parent window - * - * #HildonTimePicker shows time picker dialog. The close button is placed - * in the dialog's action area and time picker is placed in dialogs vbox. - * The actual time picker consists of two #GtkLabel fields - one for hours - * and one for minutes - and an AM/PM button. A colon (:) is placed - * between hour and minute fields. - * - * Returns: pointer to a new #HildonTimePicker widget. - */ -GtkWidget* -hildon_time_picker_new (GtkWindow *parent) -{ - GtkWidget *widget = g_object_new (HILDON_TYPE_TIME_PICKER, - "minutes", 360, NULL ); - - if (parent) - gtk_window_set_transient_for (GTK_WINDOW(widget), parent); - - return GTK_WIDGET (widget); -} - -/** - * hildon_time_picker_set_time: - * @picker: the #HildonTimePicker widget - * @hours: hours - * @minutes: minutes - * - * Sets the time of the #HildonTimePicker widget. - */ -void -hildon_time_picker_set_time (HildonTimePicker *picker, - guint hours, - guint minutes ) -{ - g_return_if_fail (HILDON_IS_TIME_PICKER(picker)); - hildon_time_picker_change_time (picker, hours * MINS_IN_1H + minutes); -} - -/** - * hildon_time_picker_get_time: - * @picker: the #HildonTimePicker widget - * @hours: hours - * @minutes: minutes - * - * Gets the time of the #HildonTimePicker widget. - */ -void -hildon_time_picker_get_time (HildonTimePicker *picker, - guint *hours, - guint *minutes ) -{ - guint current; - g_return_if_fail (HILDON_IS_TIME_PICKER (picker)); - - HildonTimePickerPrivate *priv = HILDON_TIME_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - current = priv->minutes; - *hours = current / MINS_IN_1H; - *minutes = current % MINS_IN_1H; -} - - diff --git a/hildon/hildon-time-picker.h b/hildon/hildon-time-picker.h deleted file mode 100644 index de1f716..0000000 --- a/hildon/hildon-time-picker.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_TIME_PICKER_H__ -#define __HILDON_TIME_PICKER_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -typedef struct _HildonTimePicker HildonTimePicker; - -typedef struct _HildonTimePickerClass HildonTimePickerClass; - -#define HILDON_TYPE_TIME_PICKER \ - (hildon_time_picker_get_type()) - -#define HILDON_TIME_PICKER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_TIME_PICKER, \ - HildonTimePicker)) - -#define HILDON_TIME_PICKER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - HILDON_TYPE_TIME_PICKER,\ - HildonTimePickerClass)) - -#define HILDON_IS_TIME_PICKER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, \ - HILDON_TYPE_TIME_PICKER)) - -#define HILDON_IS_TIME_PICKER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass),\ - HILDON_TYPE_TIME_PICKER)) - -#define HILDON_TIME_PICKER_GET_CLASS(obj) \ - ((HildonTimePickerClass *) G_OBJECT_GET_CLASS(obj)) - -struct _HildonTimePicker -{ - GtkDialog parent; -}; - -struct _HildonTimePickerClass -{ - GtkDialogClass parent_class; -}; - -GType G_GNUC_CONST -hildon_time_picker_get_type (void); - -GtkWidget* -hildon_time_picker_new (GtkWindow *parent); - -void -hildon_time_picker_set_time (HildonTimePicker *picker, - guint hours, - guint minutes); - -void -hildon_time_picker_get_time (HildonTimePicker *picker, - guint *hours, - guint *minutes); - -G_END_DECLS - -#endif /* __HILDON_TIME_PICKER_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-touch-selector-entry.c b/hildon/hildon-touch-selector-entry.c index 5e9c9a6..8a7bb5d 100644 --- a/hildon/hildon-touch-selector-entry.c +++ b/hildon/hildon-touch-selector-entry.c @@ -173,28 +173,6 @@ hildon_touch_selector_entry_class_init (HildonTouchSelectorEntryClass *klass) object_class->finalize = hildon_touch_selector_entry_finalize; /** - * HildonTouchSelectorEntry:text-column: - * - * A column in the data source model to get the strings from. - * - * This property is deprecated. Use HildonTouchSelectorColumn:text-column - * instead. Use hildon_touch_selector_entry_set_text_column() and - * hildon_touch_selector_entry_get_text_column() to manage it. - * - * Deprecated: use HildonTouchSelectorColumn:text-column instead - * - * Since: 2.2 - **/ - g_object_class_install_property (G_OBJECT_CLASS (klass), - PROP_TEXT_COLUMN, - g_param_spec_int ("text-column", - "Text Column", - "A column in the data source model to get the strings from.", - -1, - G_MAXINT, - -1, - G_PARAM_READWRITE)); - /** * HildonTouchSelectorEntry:smart-match: * * Whether the widget should suggest an element if an approximate match is found. diff --git a/hildon/hildon-touch-selector.c b/hildon/hildon-touch-selector.c index 2a04ead..fbba81c 100644 --- a/hildon/hildon-touch-selector.c +++ b/hildon/hildon-touch-selector.c @@ -171,8 +171,6 @@ * a flexible management of the cellrenderers in each #HildonTouchSelector column. */ -#undef HILDON_DISABLE_DEPRECATED - #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -1683,64 +1681,6 @@ hildon_touch_selector_remove_column (HildonTouchSelector * selector, gint column } /** - * hildon_touch_selector_set_column_attributes: - * @selector: a #HildonTouchSelector - * @num_column: the number of the column whose attributes we're setting - * @cell_renderer: the #GtkCellRendere we're setting the attributes of - * @Varargs: A %NULL-terminated list of attributes. - * - * Sets the attributes for the given column. The attributes must be given - * in attribute/column pairs, just like in gtk_tree_view_column_set_attributes(). - * All existing attributes are removed and replaced with the new ones. - * - * Deprecated: #HildonTouchSelectorColumn implements #GtkCellLayout, use this - * interface instead. See - * hildon_touch_selector_get_column(). - * - * Since: 2.2 - **/ -void -hildon_touch_selector_set_column_attributes (HildonTouchSelector * selector, - gint num_column, - GtkCellRenderer * cell_renderer, - ...) -{ - va_list args; - GtkTreeViewColumn *tree_column = NULL; - HildonTouchSelectorColumn *current_column = NULL; - gchar *attribute = NULL; - gint value = 0; - - g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector)); - g_return_if_fail (num_column < - hildon_touch_selector_get_num_columns (selector)); - - current_column = g_slist_nth_data (selector->priv->columns, num_column); - - tree_column = gtk_tree_view_get_column (current_column->priv->tree_view, 0); - gtk_tree_view_remove_column (current_column->priv->tree_view, tree_column); - - tree_column = gtk_tree_view_column_new (); - gtk_tree_view_column_pack_start (tree_column, cell_renderer, TRUE); - - va_start (args, cell_renderer); - attribute = va_arg (args, gchar *); - - gtk_tree_view_column_clear_attributes (tree_column, cell_renderer); - - while (attribute != NULL) { - value = va_arg (args, gint); - gtk_tree_view_column_add_attribute (tree_column, cell_renderer, - attribute, value); - attribute = va_arg (args, gchar *); - } - - va_end (args); - - gtk_tree_view_append_column (current_column->priv->tree_view, tree_column); -} - -/** * hildon_touch_selector_get_num_columns: * @selector: a #HildonTouchSelector * diff --git a/hildon/hildon-touch-selector.h b/hildon/hildon-touch-selector.h index b6da8f9..14ade39 100644 --- a/hildon/hildon-touch-selector.h +++ b/hildon/hildon-touch-selector.h @@ -125,13 +125,6 @@ hildon_touch_selector_append_column (HildonTouchSelector *selector, GtkTreeModel *model, GtkCellRenderer *cell_renderer, ...); -#ifndef HILDON_DISABLE_DEPRECATED -void -hildon_touch_selector_set_column_attributes (HildonTouchSelector *selector, - gint num_column, - GtkCellRenderer *cell_renderer, - ...); -#endif gboolean hildon_touch_selector_remove_column (HildonTouchSelector *selector, diff --git a/hildon/hildon-volumebar-private.h b/hildon/hildon-volumebar-private.h deleted file mode 100644 index 62a5095..0000000 --- a/hildon/hildon-volumebar-private.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_VOLUMEBAR_PRIVATE__ -#define __HILDON_VOLUMEBAR_PRIVATE__ - -#include <gtk/gtk.h> - -#include "hildon-volumebar-range.h" - -G_BEGIN_DECLS - -#define HILDON_VOLUMEBAR_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_VOLUMEBAR, HildonVolumebarPrivate)); - -typedef struct _HildonVolumebarPrivate HildonVolumebarPrivate; - -struct _HildonVolumebarPrivate -{ - HildonVolumebarRange *volumebar; - GtkToggleButton *tbutton; - gboolean is_toolbar; /* is inside toolbar (for horizontal volumebar) */ - GdkWindow *event_window; /* input-only window to catch insensitive presses */ -}; - -void G_GNUC_INTERNAL -hildon_volumebar_mute_toggled (HildonVolumebar * self); - -void G_GNUC_INTERNAL -hildon_volumebar_level_change (HildonVolumebar *self); - -G_END_DECLS - -#endif /* __HILDON_VOLUMEBAR_PRIVATE__ */ diff --git a/hildon/hildon-volumebar-range.c b/hildon/hildon-volumebar-range.c deleted file mode 100644 index 11ff1f1..0000000 --- a/hildon/hildon-volumebar-range.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-volumebar-range - * @short_description: This widget is an "workhorse" for #HildonVolumebar - * widget. It is not designed to be used as a standalone widget. - * - * Purpose of this widget is to act as an "container" for GtkScale - * widget. #HildonVolumebarRange changes some event parameters so - * that #HildonVolumebar can meet its specifications. - * - * Currently #HildonVolumebarRange models range of [0..100]. - * - * <note> - * <para> - * #HildonVolumebarRange has been deprecated since Hildon 2.2 and should not - * be used in newly written code. See - * <link linkend="hildon-migrating-volume-bar">Migrating Volume Bars</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - */ - -#include <gdk/gdkkeysyms.h> - -#include "hildon-volumebar-range.h" - -#define VOLUMEBAR_RANGE_INITIAL_VALUE 50.0 - -#define VOLUMEBAR_RANGE_MINIMUM_VALUE 0.0 - -#define VOLUMEBAR_RANGE_MAXIMUM_VALUE 100.0 - -#define VOLUMEBAR_RANGE_STEP_INCREMENT_VALUE 5.0 - -#define VOLUMEBAR_RANGE_PAGE_INCREMENT_VALUE 5.0 - -#define VOLUMEBAR_RANGE_PAGE_SIZE_VALUE 0.0 - -#define CHANGE_THRESHOLD 0.001 - -static GtkScaleClass* parent_class; - -static void -hildon_volumebar_range_class_init (HildonVolumebarRangeClass* - volumerange_class); - -static void -hildon_volumebar_range_init (HildonVolumebarRange* - volumerange); - -static void -hildon_volumebar_range_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); - -static void -hildon_volumebar_range_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static gint -hildon_volumebar_range_button_press_event (GtkWidget *widget, - GdkEventButton *event); - -static gint -hildon_volumebar_range_button_release_event (GtkWidget *widget, - GdkEventButton *event); - -static gboolean -hildon_volumebar_range_keypress (GtkWidget *widget, - GdkEventKey *event); - -enum -{ - PROP_0, - PROP_LEVEL -}; - -/** - * hildon_volumebar_range_get_type: - * - * Initializes and returns the type of a hildon volumebar range. - * - * Returns: GType of #HildonVolumebarRange - */ -GType G_GNUC_CONST -hildon_volumebar_range_get_type (void) -{ - static GType volumerange_type = 0; - - if (!volumerange_type) { - static const GTypeInfo volumerange_info = { - sizeof (HildonVolumebarRangeClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_volumebar_range_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonVolumebarRange), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_volumebar_range_init, - }; - volumerange_type = g_type_register_static (GTK_TYPE_SCALE, - "HildonVolumebarRange", - &volumerange_info, 0); - } - - return volumerange_type; -} - -static void -hildon_volumebar_range_class_init (HildonVolumebarRangeClass *volumerange_class) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (volumerange_class); - GObjectClass *object_class = G_OBJECT_CLASS (volumerange_class); - - parent_class = g_type_class_peek_parent (volumerange_class); - - widget_class->button_press_event = - hildon_volumebar_range_button_press_event; - widget_class->button_release_event = - hildon_volumebar_range_button_release_event; - widget_class->key_press_event = hildon_volumebar_range_keypress; - - object_class->set_property = hildon_volumebar_range_set_property; - object_class->get_property = hildon_volumebar_range_get_property; - - /** - * HildonVolumebarRange:level: - * - * Current volume level. - */ - g_object_class_install_property (object_class, - PROP_LEVEL, - g_param_spec_double ("level", - "Level", - "Current volume level", - VOLUMEBAR_RANGE_MINIMUM_VALUE, - VOLUMEBAR_RANGE_MAXIMUM_VALUE, - VOLUMEBAR_RANGE_INITIAL_VALUE, - G_PARAM_READWRITE)); - return; -} - -static void -hildon_volumebar_range_init (HildonVolumebarRange *volumerange) -{ - /* do nothing. */ -} - -static void -hildon_volumebar_range_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonVolumebarRange *range = HILDON_VOLUMEBAR_RANGE (object); - - switch (prop_id) { - case PROP_LEVEL: - hildon_volumebar_range_set_level (range, g_value_get_double (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - - } -} - -static void -hildon_volumebar_range_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - HildonVolumebarRange *range = HILDON_VOLUMEBAR_RANGE (object); - - switch (prop_id) { - - case PROP_LEVEL: - g_value_set_double (value, hildon_volumebar_range_get_level(range)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - } -} - -static gboolean -hildon_volumebar_range_keypress (GtkWidget *widget, - GdkEventKey *event) -{ - /* Accept arrow keys only if they match the orientation of the widget */ - if (GTK_RANGE (widget)->orientation == GTK_ORIENTATION_HORIZONTAL) - { - if (event->keyval == GDK_Up || event->keyval == GDK_Down) { - return FALSE; - } - } - else - { - if (event->keyval == GDK_Left || event->keyval == GDK_Right) { - return FALSE; - } - } - - return ((GTK_WIDGET_CLASS (parent_class)->key_press_event) (widget, - event)); -} - -GtkWidget* -hildon_volumebar_range_new (GtkOrientation orientation) -{ - GtkAdjustment * adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (VOLUMEBAR_RANGE_INITIAL_VALUE, - VOLUMEBAR_RANGE_MINIMUM_VALUE, - VOLUMEBAR_RANGE_MAXIMUM_VALUE, - VOLUMEBAR_RANGE_STEP_INCREMENT_VALUE, - VOLUMEBAR_RANGE_PAGE_INCREMENT_VALUE, - VOLUMEBAR_RANGE_PAGE_SIZE_VALUE)); - - HildonVolumebarRange *self = - g_object_new(HILDON_TYPE_VOLUMEBAR_RANGE, - "adjustment", adjustment, - NULL); - - GTK_RANGE (self)->orientation = orientation; - - /* Default vertical range is upside down for purposes of this widget */ - gtk_range_set_inverted (GTK_RANGE (self), - (orientation == GTK_ORIENTATION_VERTICAL)); - - return GTK_WIDGET(self); -} - -gdouble -hildon_volumebar_range_get_level (HildonVolumebarRange *self) -{ - g_return_val_if_fail (HILDON_IS_VOLUMEBAR_RANGE(self), -1.0); - - return gtk_adjustment_get_value (gtk_range_get_adjustment(GTK_RANGE (self))); -} - -void -hildon_volumebar_range_set_level (HildonVolumebarRange * self, - gdouble level) -{ - GtkAdjustment *adjustment; - - g_return_if_fail (HILDON_IS_VOLUMEBAR_RANGE (self)); - - adjustment = gtk_range_get_adjustment (GTK_RANGE (self)); - - /* Check that value has actually changed. Note that it's not safe to - * just compare if floats are equivalent or not */ - if (ABS (gtk_adjustment_get_value (adjustment) - level) > CHANGE_THRESHOLD) { - gtk_adjustment_set_value(adjustment, level); - } -} - -static gint -hildon_volumebar_range_button_press_event (GtkWidget *widget, - GdkEventButton *event) -{ - gboolean result = FALSE; - - /* FIXME: By default, clicking left mouse button on GtkRange moves the - slider by one step towards the click location. However, we want stylus - taps to move the slider to the position of the tap, which by default - is the middle button behaviour. To avoid breaking default GtkRange - behaviour, this has been implemented by faking a middle button press. */ - - event->button = (event->button == 1) ? 2 : event->button; - if (GTK_WIDGET_CLASS (parent_class)->button_press_event) { - result = GTK_WIDGET_CLASS (parent_class)->button_press_event(widget, event); - } - - return result; -} - -static gint -hildon_volumebar_range_button_release_event (GtkWidget *widget, - GdkEventButton *event) -{ - gboolean result = FALSE; - - /* FIXME: By default, clicking left mouse button on GtkRange moves the - slider by one step towards the click location. However, we want stylus - taps to move the slider to the position of the tap, which by default - is the middle button behaviour. To avoid breaking default GtkRange - behaviour, this has been implemented by faking a middle button press. */ - - event->button = event->button == 1 ? 2 : event->button; - if (GTK_WIDGET_CLASS (parent_class)->button_release_event) { - result = GTK_WIDGET_CLASS(parent_class)->button_release_event(widget, event); - } - - return result; -} - diff --git a/hildon/hildon-volumebar-range.h b/hildon/hildon-volumebar-range.h deleted file mode 100644 index f61c412..0000000 --- a/hildon/hildon-volumebar-range.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_VOLUMEBAR_RANGE_H__ -#define __HILDON_VOLUMEBAR_RANGE_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -/** - * HILDON_TYPE_VOLUMEBAR_RANGE - * - * Macro for getting type of volumebar range. - */ -#define HILDON_TYPE_VOLUMEBAR_RANGE \ - (hildon_volumebar_range_get_type()) - -#define HILDON_VOLUMEBAR_RANGE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_VOLUMEBAR_RANGE, HildonVolumebarRange)) - -#define HILDON_VOLUMEBAR_RANGE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_VOLUMEBAR_RANGE, HildonVolumebarRangeClass)) - -#define HILDON_IS_VOLUMEBAR_RANGE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj,\ - HILDON_TYPE_VOLUMEBAR_RANGE)) - -#define HILDON_IS_VOLUMEBAR_RANGE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - HILDON_TYPE_VOLUMEBAR_RANGE)) - -typedef struct _HildonVolumebarRange HildonVolumebarRange; - -typedef struct _HildonVolumebarRangeClass HildonVolumebarRangeClass; - -struct _HildonVolumebarRange -{ - GtkScale scale; -}; - -struct _HildonVolumebarRangeClass -{ - GtkScaleClass parent_class; -}; - -GType G_GNUC_CONST -hildon_volumebar_range_get_type (void); - -GtkWidget* -hildon_volumebar_range_new (GtkOrientation orientation); - -gdouble -hildon_volumebar_range_get_level (HildonVolumebarRange *self); - -void -hildon_volumebar_range_set_level (HildonVolumebarRange *self, - gdouble level); - -G_END_DECLS - -#endif /* __HILDON_VOLUMEBAR_RANGE_H__ */ diff --git a/hildon/hildon-volumebar.c b/hildon/hildon-volumebar.c deleted file mode 100644 index 42ae2a7..0000000 --- a/hildon/hildon-volumebar.c +++ /dev/null @@ -1,806 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-volumebar - * @short_description: Base class for widgets that display a volume bar. - * @see_also: #HildonHVolumebar, #HildonVVolumebar - * - * #HildonVolumebar is a base class for widgets that display a volume bar that - * allows increasing or decreasing volume within a predefined range, and muting - * the volume when users click the mute icon. - * - * <note> - * <para> - * #HildonVolumebar has been deprecated since Hildon 2.2 and should not - * be used in newly written code. See - * <link linkend="hildon-migrating-volume-bar">Migrating Volume Bars</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gdk/gdkkeysyms.h> - -#include "hildon-volumebar.h" -#include "hildon-volumebar-range.h" -#include "hildon-volumebar-private.h" - -static GtkContainerClass* parent_class; - -static void -hildon_volumebar_class_init (HildonVolumebarClass* volumebar_class); - -static void -hildon_volumebar_init (HildonVolumebar* volumebar); - -static void -hildon_child_forall (GtkContainer * container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void -hildon_volumebar_destroy (GtkObject *self); - -static void -hildon_volumebar_set_property (GObject* object, - guint prop_id, - const GValue* value, - GParamSpec* pspec); - -static void -hildon_volumebar_get_property (GObject * object, - guint prop_id, - GValue* value, - GParamSpec* pspec); - -static void -mute_toggled (HildonVolumebar *self); - -static gboolean -hildon_volumebar_key_press (GtkWidget* widget, - GdkEventKey* event); - -static void -hildon_volumebar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static void -hildon_volumebar_realize (GtkWidget *widget); - -static void -hildon_volumebar_unrealize (GtkWidget *widget); - -static void -hildon_volumebar_map (GtkWidget *widget); - -static void -hildon_volumebar_unmap (GtkWidget *widget); - -static void -hildon_volumebar_grab_focus (GtkWidget *widget); - -static gboolean -hildon_volumebar_focus (GtkWidget *widget, - GtkDirectionType direction); - -static void -hildon_volumebar_notify (GObject *self, GParamSpec *param); - -enum -{ - MUTE_TOGGLED_SIGNAL, - LEVEL_CHANGED_SIGNAL, - LAST_SIGNAL -}; - -enum { - PROP_0, - PROP_HILDON_HAS_MUTE, - PROP_HILDON_LEVEL, - PROP_HILDON_MUTE -}; - -static guint signals [LAST_SIGNAL] = { 0 }; - -/** - * hildon_volumebar_get_type: - * - * Initializes and returns the type of a hildon volumebar. - * - * Returns: GType of #HildonVolumebar - */ -GType G_GNUC_CONST -hildon_volumebar_get_type (void) -{ - static GType volumebar_type = 0; - - if (!volumebar_type) { - static const GTypeInfo volumebar_info = { - sizeof(HildonVolumebarClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_volumebar_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof(HildonVolumebar), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_volumebar_init, - }; - volumebar_type = g_type_register_static(GTK_TYPE_CONTAINER, - "HildonVolumebar", - &volumebar_info, 0); - } - return volumebar_type; -} - -static void -hildon_volumebar_class_init (HildonVolumebarClass *volumebar_class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (volumebar_class); - GtkObjectClass *object_class = GTK_OBJECT_CLASS (volumebar_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (volumebar_class); - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (volumebar_class); - - parent_class = g_type_class_peek_parent (volumebar_class); - - g_type_class_add_private (volumebar_class, - sizeof (HildonVolumebarPrivate)); - - /* Because we derived our widget from GtkContainer, we should also - * override forall method - */ - volumebar_class->mute_toggled = mute_toggled; - container_class->forall = hildon_child_forall; - widget_class->size_allocate = hildon_volumebar_size_allocate; - widget_class->realize = hildon_volumebar_realize; - widget_class->unrealize = hildon_volumebar_unrealize; - widget_class->map = hildon_volumebar_map; - widget_class->unmap = hildon_volumebar_unmap; - widget_class->grab_focus = hildon_volumebar_grab_focus; - widget_class->focus = hildon_volumebar_focus; - widget_class->key_press_event = hildon_volumebar_key_press; - object_class->destroy = hildon_volumebar_destroy; - - signals[MUTE_TOGGLED_SIGNAL] = g_signal_new ("mute_toggled", - G_OBJECT_CLASS_TYPE - (object_class), - G_SIGNAL_RUN_LAST | - G_SIGNAL_ACTION, - G_STRUCT_OFFSET - (HildonVolumebarClass, - mute_toggled), NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[LEVEL_CHANGED_SIGNAL] = g_signal_new ("level_changed", - G_OBJECT_CLASS_TYPE - (object_class), - G_SIGNAL_RUN_LAST | - G_SIGNAL_ACTION, - G_STRUCT_OFFSET - (HildonVolumebarClass, - level_changed), NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - gobject_class->notify = hildon_volumebar_notify; - gobject_class->set_property = hildon_volumebar_set_property; - gobject_class->get_property = hildon_volumebar_get_property; - - /** - * HildonVolumebar:has-mute: - * - * Whether the mute button is visibile. - */ - g_object_class_install_property (gobject_class, - PROP_HILDON_HAS_MUTE, - g_param_spec_boolean ("has_mute", - "Show/Hide the mute button", - "Whether the mute button is visible. Default value: TRUE", - TRUE, - G_PARAM_CONSTRUCT | G_PARAM_READWRITE)); - - /** - * HildonVolumebar:level: - * - * Current volume level. - */ - g_object_class_install_property (gobject_class, - PROP_HILDON_LEVEL, - g_param_spec_double ("level", - "Level", - "Current volume level", - 0.0, - 100.0, - 50.0, - G_PARAM_READWRITE)); - - /** - * HildonVolumebar:mute: - * - * Whether volume is muted. - */ - g_object_class_install_property (gobject_class, - PROP_HILDON_MUTE, - g_param_spec_boolean ("mute", - "Mute", - "Whether volume is muted", - FALSE, - G_PARAM_READWRITE)); -} - -static void -hildon_volumebar_init (HildonVolumebar *volumebar) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(volumebar); - g_assert (priv); - - /* Should set GTK_NO_WINDOW flag, because widget is derived from - GtkContainer */ - GTK_WIDGET_SET_FLAGS (GTK_WIDGET (volumebar), GTK_NO_WINDOW); - GTK_WIDGET_SET_FLAGS (GTK_WIDGET (volumebar), GTK_CAN_FOCUS); - - /* Initialize mute button */ - priv->tbutton = GTK_TOGGLE_BUTTON (gtk_toggle_button_new ()); - g_object_set (G_OBJECT (priv->tbutton), "can-focus", FALSE, NULL); -} - -static void -hildon_volumebar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(widget); - g_assert (priv); - - if (GTK_WIDGET_CLASS (parent_class)->size_allocate) - GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); - - if (GTK_WIDGET_REALIZED (widget)) - gdk_window_move_resize (priv->event_window, - allocation->x, allocation->y, - allocation->width, allocation->height); -} - -static void -hildon_volumebar_realize (GtkWidget *widget) -{ - HildonVolumebarPrivate *priv; - GdkWindowAttr attributes; - gint attributes_mask; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE (widget); - g_assert (priv); - - GTK_WIDGET_CLASS (parent_class)->realize (widget); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_ONLY; - attributes.event_mask = GDK_BUTTON_PRESS_MASK; - - attributes_mask = GDK_WA_X | GDK_WA_Y; - - priv->event_window = gdk_window_new (widget->window, - &attributes, attributes_mask); - - gdk_window_set_user_data (priv->event_window, widget); -} - -static void -hildon_volumebar_unrealize (GtkWidget *widget) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(widget); - g_assert (priv); - - if (priv->event_window) { - gdk_window_set_user_data (priv->event_window, NULL); - gdk_window_destroy (priv->event_window); - priv->event_window = NULL; - } - - GTK_WIDGET_CLASS (parent_class)->unrealize(widget); -} - -static void -hildon_volumebar_map (GtkWidget *widget) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(widget); - g_assert (priv); - - GTK_WIDGET_CLASS (parent_class)->map (widget); - - /* the event window must be on top of all other widget windows, so show it - * last */ - if (! GTK_WIDGET_SENSITIVE (widget)) - gdk_window_show (priv->event_window); -} - -static void -hildon_volumebar_unmap (GtkWidget *widget) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE (widget); - g_assert (priv); - - gdk_window_hide (priv->event_window); - - GTK_WIDGET_CLASS (parent_class)->unmap(widget); -} - -static void -hildon_volumebar_grab_focus (GtkWidget *widget) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE (widget); - g_assert (priv); - - if (GTK_WIDGET_CAN_FOCUS (widget)) { - if (gtk_toggle_button_get_active (priv->tbutton)) - gtk_widget_grab_focus (GTK_WIDGET (priv->tbutton)); - else - gtk_widget_grab_focus (GTK_WIDGET (priv->volumebar)); - } -} - -static gboolean -hildon_volumebar_focus (GtkWidget *widget, - GtkDirectionType direction) -{ - HildonVolumebarPrivate *priv; - GtkOrientation orientation; - gboolean has_focus; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE (widget); - g_assert (priv); - - orientation = GTK_RANGE (priv->volumebar)->orientation; - - has_focus = (GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (priv->volumebar)) || - GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (priv->tbutton))); - - switch (direction) { - case GTK_DIR_UP: - case GTK_DIR_DOWN: - case GTK_DIR_TAB_FORWARD: - case GTK_DIR_TAB_BACKWARD: - if (has_focus && orientation == GTK_ORIENTATION_HORIZONTAL) - return FALSE; - break; - - case GTK_DIR_LEFT: - case GTK_DIR_RIGHT: - if (has_focus && orientation == GTK_ORIENTATION_VERTICAL) - return FALSE; - break; - - default: - break; - } - - return GTK_WIDGET_CLASS (parent_class)->focus (widget, direction); -} - -static void -hildon_child_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE (container); - g_assert (callback != NULL); - g_assert (priv); - - /* No external children */ - if (! include_internals) - return; - - /* Execute callback for both internals */ - (*callback) (GTK_WIDGET (priv->tbutton), callback_data); - (*callback) (GTK_WIDGET (priv->volumebar), callback_data); -} - -static void -hildon_volumebar_notify (GObject *self, - GParamSpec *param) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(self); - g_assert (priv); - - if (g_str_equal (param->name, "can-focus")) { - /* call set_mute() because that updates the widget's UI state */ - hildon_volumebar_set_mute (HILDON_VOLUMEBAR (self), - hildon_volumebar_get_mute (HILDON_VOLUMEBAR (self))); - } - - if (GTK_WIDGET_MAPPED (self)) { - /* show/hide the event window on sensitivity change */ - if (g_str_equal (param->name, "sensitive")) { - if (GTK_WIDGET_SENSITIVE (self)) - gdk_window_hide (priv->event_window); - else - gdk_window_show (priv->event_window); - } - } - - if (G_OBJECT_CLASS(parent_class)->notify) - G_OBJECT_CLASS(parent_class)->notify (self, param); -} - -static void -hildon_volumebar_destroy (GtkObject *self) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(self); - g_assert (priv); - - if (priv->tbutton) { - gtk_widget_unparent (GTK_WIDGET (priv->tbutton)); - priv->tbutton = NULL; - } - if (priv->volumebar) { - gtk_widget_unparent (GTK_WIDGET (priv->volumebar)); - priv->volumebar = NULL; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - GTK_OBJECT_CLASS (parent_class)->destroy (self); -} - -static void -hildon_volumebar_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(object); - g_assert (priv); - - switch (prop_id) { - - case PROP_HILDON_HAS_MUTE: - /* Mute button always exists but might be hidden */ - if (g_value_get_boolean (value)) - gtk_widget_show (GTK_WIDGET (priv->tbutton)); - else - gtk_widget_hide (GTK_WIDGET (priv->tbutton)); - break; - - case PROP_HILDON_LEVEL: - hildon_volumebar_set_level (HILDON_VOLUMEBAR (object), - g_value_get_double (value)); - break; - - case PROP_HILDON_MUTE: - hildon_volumebar_set_mute (HILDON_VOLUMEBAR (object), - g_value_get_boolean (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - - break; - } -} - -static void -hildon_volumebar_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - HildonVolumebarPrivate *priv; - HildonVolumebar *vb; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(object); - g_assert (priv); - - vb = HILDON_VOLUMEBAR (object); - - switch (prop_id) { - - case PROP_HILDON_HAS_MUTE: - g_value_set_boolean (value, GTK_WIDGET_VISIBLE (priv->tbutton)); - break; - - case PROP_HILDON_LEVEL: - g_value_set_double (value, hildon_volumebar_get_level (vb)); - break; - - case PROP_HILDON_MUTE: - g_value_set_boolean (value, hildon_volumebar_get_mute (vb)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - break; - - } -} - -/** - * hildon_volumebar_set_level: - * @self: volume bar to change level on - * @level: new level - * - * Sets new volume level for this #HildonVolumebar. - */ -void -hildon_volumebar_set_level (HildonVolumebar *self, - gdouble level) -{ - HildonVolumebarPrivate *priv; - - g_return_if_fail(HILDON_IS_VOLUMEBAR (self)); - - priv = HILDON_VOLUMEBAR_GET_PRIVATE (self); - g_assert (priv); - - hildon_volumebar_range_set_level (priv->volumebar, level); -} - -/** - * hildon_volumebar_get_level: - * @self: volume bar to query level on - * - * Gets the volume level of this #HildonVolumebar. - * - * Returns: volume level or -1 on error - */ -gdouble -hildon_volumebar_get_level (HildonVolumebar *self) -{ - HildonVolumebarPrivate *priv; - - g_return_val_if_fail(HILDON_IS_VOLUMEBAR (self), -1); - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(self); - g_assert (priv); - - return hildon_volumebar_range_get_level (priv->volumebar); -} - -/** - * hildon_volumebar_set_mute: - * @self: volume bar to work on - * @mute: mute ON/OFF - * - * Sets mute status for this #HildonVolumebar. - */ -void -hildon_volumebar_set_mute (HildonVolumebar *self, - gboolean mute) -{ - HildonVolumebarPrivate *priv; - gboolean has_focus; - - g_return_if_fail (HILDON_IS_VOLUMEBAR (self)); - - priv = HILDON_VOLUMEBAR_GET_PRIVATE (self); - g_assert (priv); - - has_focus = (GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (priv->volumebar)) || - GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (priv->tbutton))); - - /* Slider should be insensitive when mute is on */ - gtk_widget_set_sensitive (GTK_WIDGET (priv->volumebar), !mute); - - if (mute) { - /* Make mute button focusable since the slider isn't anymore */ - g_object_set (G_OBJECT (priv->tbutton), "can-focus", TRUE, NULL); - - if (has_focus) - gtk_widget_grab_focus (GTK_WIDGET (priv->tbutton)); - } - else - { - g_object_set (G_OBJECT (priv->tbutton), "can-focus", FALSE, NULL); - - if (has_focus) - gtk_widget_grab_focus (GTK_WIDGET (priv->volumebar)); - } - - /* Update mute button state and redraw */ - gtk_toggle_button_set_active (priv->tbutton, mute); -} - -/** - * hildon_volumebar_get_mute: - * @self: volume bar to query mute status - * - * Gets mute status of this #HildonVolumebar (ON/OFF). - * - * Returns: Mute status as #gboolean value. - */ -gboolean -hildon_volumebar_get_mute (HildonVolumebar *self) -{ - HildonVolumebarPrivate *priv; - - g_return_val_if_fail (HILDON_IS_VOLUMEBAR (self), TRUE); - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(self); - g_assert (priv); - - return gtk_toggle_button_get_active (priv->tbutton); -} - -/** - * hildon_volumebar_get_adjustment - * @self : a #HildonVolumebar - * - * Gets the GtkAdjustment used in volume bar. This can be handy - * to pass to hildon_appview_set_connected_adjustment which - * will allow changing the volume with 'increase' / 'decrease' - * hardware buttons. - * - * Returns: a #GtkAdjustment used by volume bar. - */ -GtkAdjustment* -hildon_volumebar_get_adjustment (HildonVolumebar *self) -{ - HildonVolumebarPrivate *priv; - - g_return_val_if_fail(HILDON_IS_VOLUMEBAR(self), NULL); - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(self); - g_assert (priv); - - return gtk_range_get_adjustment (GTK_RANGE (priv->volumebar)); -} - -static void -mute_toggled (HildonVolumebar *self) -{ - /* This looks like no-op, but it still does something meaningfull! - set_mute also updates the ui to match new state that - is already reported by get_mute */ - - hildon_volumebar_set_mute (self, hildon_volumebar_get_mute (self)); -} - -static gboolean -hildon_volumebar_key_press (GtkWidget *widget, - GdkEventKey *event) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(widget); - g_assert (priv != NULL); - - /* Enter key toggles mute button (unless it is hidden) */ - if (event->keyval == GDK_Return && GTK_WIDGET_VISIBLE (priv->tbutton)) { - gtk_toggle_button_set_active (priv->tbutton, - ! hildon_volumebar_get_mute(HILDON_VOLUMEBAR(widget))); - - return TRUE; - } - - return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event); -} - -/* - * Sends mute-toggled signal to widget, used as a callback in derived classes. - */ -void G_GNUC_INTERNAL -hildon_volumebar_mute_toggled (HildonVolumebar * self) -{ - g_return_if_fail (HILDON_IS_VOLUMEBAR (self)); - /* FIXME Emit by id */ - g_signal_emit_by_name (self, "mute_toggled"); -} - -void G_GNUC_INTERNAL -hildon_volumebar_level_change (HildonVolumebar *self) -{ - g_return_if_fail (HILDON_IS_VOLUMEBAR (self)); - - /* FIXME Use numerical val, id */ - g_signal_emit_by_name (GTK_WIDGET (self), "level_changed"); -} - -/** - * hildon_volumebar_set_range_insensitive_message: - * @widget: A @GtkWidget to assign the banner to - * @message: A message to display to the user - * - * Used to asign an insensitive message to the slider of the given volumebar. - * It simply calls hildon_helper_set_insensitive_message on the slider/range of - * the volumebar. - * - * Deprecated: As of hildon 2.2, it is strongly discouraged to use insensitive messages. - */ -void -hildon_volumebar_set_range_insensitive_message (HildonVolumebar *widget, - const gchar *message) -{ - g_return_if_fail (HILDON_IS_VOLUMEBAR (widget)); - - HildonVolumebarPrivate *priv; - priv = HILDON_VOLUMEBAR_GET_PRIVATE (widget); - - hildon_helper_set_insensitive_message ((GtkWidget *) priv->volumebar, message); -} - -/** - * hildon_volumebar_set_range_insensitive_messagef: - * @widget: A @GtkWidget to assign the banner to - * @format : a printf-like format string - * @varargs : arguments for the format string - * - * A helper printf-like variant of hildon_helper_set_insensitive_message. - * - * Deprecated: As of hildon 2.2, it is strongly discouraged to use insensitive messages. - */ -void -hildon_volumebar_set_range_insensitive_messagef (HildonVolumebar *widget, - const gchar *format, - ...) -{ - g_return_if_fail (HILDON_IS_VOLUMEBAR (widget)); - - HildonVolumebarPrivate *priv; - priv = HILDON_VOLUMEBAR_GET_PRIVATE (widget); - - gchar *message; - va_list args; - - va_start (args, format); - message = g_strdup_vprintf (format, args); - va_end (args); - - hildon_helper_set_insensitive_message ((GtkWidget *) priv->volumebar, message); - - g_free (message); -} - - diff --git a/hildon/hildon-volumebar.h b/hildon/hildon-volumebar.h deleted file mode 100644 index 9cead0c..0000000 --- a/hildon/hildon-volumebar.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_VOLUMEBAR_H__ -#define __HILDON_VOLUMEBAR_H__ - -#include <gtk/gtk.h> - -#include "hildon-helper.h" - -G_BEGIN_DECLS - -#define HILDON_TYPE_VOLUMEBAR \ - (hildon_volumebar_get_type()) - -#define HILDON_VOLUMEBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj,\ - HILDON_TYPE_VOLUMEBAR, HildonVolumebar)) - -#define HILDON_VOLUMEBAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_VOLUMEBAR, HildonVolumebarClass)) - -#define HILDON_IS_VOLUMEBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj,\ - HILDON_TYPE_VOLUMEBAR)) - -#define HILDON_IS_VOLUMEBAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_VOLUMEBAR)) - -#define HILDON_VOLUMEBAR_GET_CLASS(obj) \ - ((HildonVolumebarClass *) G_OBJECT_GET_CLASS(obj)) - -typedef struct _HildonVolumebar HildonVolumebar; - -typedef struct _HildonVolumebarClass HildonVolumebarClass; - -struct _HildonVolumebar -{ - GtkContainer parent; -}; - -struct _HildonVolumebarClass -{ - GtkContainerClass parent_class; - - /* signals */ - void (*mute_toggled) (HildonVolumebar * self); - void (*level_changed) (HildonVolumebar * self); -}; - -GType G_GNUC_CONST -hildon_volumebar_get_type (void); - -double -hildon_volumebar_get_level (HildonVolumebar *self); - -void -hildon_volumebar_set_level (HildonVolumebar *self, - gdouble level); - -gboolean -hildon_volumebar_get_mute (HildonVolumebar *self); - -void -hildon_volumebar_set_mute (HildonVolumebar *self, - gboolean mute); - -GtkAdjustment* -hildon_volumebar_get_adjustment (HildonVolumebar *self); - -#ifndef HILDON_DISABLE_DEPRECATED -void -hildon_volumebar_set_range_insensitive_message (HildonVolumebar *widget, - const gchar *message); - -void -hildon_volumebar_set_range_insensitive_messagef (HildonVolumebar *widget, - const gchar *format, - ...); -#endif - -G_END_DECLS - -#endif /* __HILDON_VOLUMEBAR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-vvolumebar.c b/hildon/hildon-vvolumebar.c deleted file mode 100644 index 5e0cec4..0000000 --- a/hildon/hildon-vvolumebar.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-vvolumebar - * @short_description: A widget that displays a vertical volume bar. - * @see_also: #HildonVolumebar, #HildonHVolumebar - * - * #HildonVVolumebar is a subclass of #HildonVolumebar. It displays a - * vertical volume bar that allows increasing or decreasing volume - * within a predefined range, and muting when users click the mute icon. - * - * <note> - * <para> - * #HildonVVolumebar has been deprecated since Hildon 2.2 and should not - * be used in newly written code. See - * <link linkend="hildon-migrating-volume-bar">Migrating Volume Bars</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * Here is an example that creates a vertical volume bar and connects - * both its signals. - * - * <example> - * <title>HildonVVolumebar example</title> - * <programlisting> - * GtkWidget *volbar = hildon_vvolumebar_new (); - * g_signal_connect (G_OBJECT (volbar), "mute_toggled", G_CALLBACK (mute_toggle), NULL); - * g_signal_connect (G_OBJECT (volbar), "level_changed", G_CALLBACK (level_change), NULL); - * </programlisting> - * </example> - */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "hildon-vvolumebar.h" -#include "hildon-volumebar-range.h" -#include "hildon-volumebar-private.h" - -/* Volume bar */ -#define DEFAULT_BAR_WIDTH 60 - -#define MINIMUM_BAR_HEIGHT 165 - -/* Toggle button */ - -#define DEFAULT_VERTICAL_TBUTTON_WIDTH 60 - -#define DEFAULT_VERTICAL_TBUTTON_HEIGHT 60 - -#define DEFAULT_ENDING_SIZE 0 - -/* Gap to leave for mute button */ - -#define HORIZONTAL_MUTE_GAP 0 - -#define VERTICAL_MUTE_GAP 0 - -static HildonVolumebarClass* parent_class; - -static void -hildon_vvolumebar_class_init (HildonVVolumebarClass * klass); - -static void -hildon_vvolumebar_init (HildonVVolumebar * vvolumebar); - -static gboolean -hildon_vvolumebar_expose (GtkWidget * widget, - GdkEventExpose * event); - -static void -hildon_vvolumebar_size_request (GtkWidget * widget, - GtkRequisition * requisition); - -static void -hildon_vvolumebar_size_allocate (GtkWidget * widget, - GtkAllocation * allocation); - -/** - * hildon_vvolumebar_get_type: - * - * Initializes and returns the type of a hildon vvolumebar. - * - * Returns: GType of #HildonVVolumebar - */ -GType G_GNUC_CONST -hildon_vvolumebar_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (HildonVVolumebarClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_vvolumebar_class_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonVVolumebar), - 0, - (GInstanceInitFunc) hildon_vvolumebar_init, - }; - type = - g_type_register_static (HILDON_TYPE_VOLUMEBAR, - "HildonVVolumebar", &info, 0); - } - return type; -} - -static void -hildon_vvolumebar_class_init (HildonVVolumebarClass *klass) -{ - GtkWidgetClass *volumebar_class = GTK_WIDGET_CLASS(klass); - - parent_class = g_type_class_peek_parent(klass); - - volumebar_class->size_request = hildon_vvolumebar_size_request; - volumebar_class->size_allocate = hildon_vvolumebar_size_allocate; - volumebar_class->expose_event = hildon_vvolumebar_expose; -} - -static void -hildon_vvolumebar_init (HildonVVolumebar *vvolumebar) -{ - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE (vvolumebar); - g_assert (priv); - - priv->volumebar = HILDON_VOLUMEBAR_RANGE (hildon_volumebar_range_new - (GTK_ORIENTATION_VERTICAL)); - - gtk_widget_set_parent (GTK_WIDGET (priv->tbutton), GTK_WIDGET (vvolumebar)); - gtk_widget_set_parent (GTK_WIDGET (priv->volumebar), GTK_WIDGET (vvolumebar)); - - gtk_scale_set_draw_value (GTK_SCALE (priv->volumebar), FALSE); - - /* Signals */ - g_signal_connect_swapped(G_OBJECT(priv->volumebar), "value-changed", - G_CALLBACK(hildon_volumebar_level_change), - vvolumebar); - - g_signal_connect_swapped(priv->tbutton, "toggled", - G_CALLBACK(hildon_volumebar_mute_toggled), vvolumebar); - - /* FIXME Not sure why this is here */ - gtk_widget_show (GTK_WIDGET (priv->volumebar)); -} - -/** - * hildon_vvolumebar_new: - * - * Creates a new #HildonVVolumebar widget. - * - * Returns: a new #HildonVVolumebar - */ -GtkWidget* -hildon_vvolumebar_new (void) -{ - return GTK_WIDGET (g_object_new(HILDON_TYPE_VVOLUMEBAR, NULL)); -} - -static gboolean -hildon_vvolumebar_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - - HildonVolumebarPrivate *priv; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(HILDON_VOLUMEBAR(widget)); - g_assert (priv); - - if (GTK_WIDGET_DRAWABLE (widget)) { - /* Paint background */ - gtk_paint_box (widget->style, widget->window, - GTK_WIDGET_STATE (priv->volumebar), GTK_SHADOW_OUT, - NULL, widget, "background", - widget->allocation.x, - widget->allocation.y, - widget->allocation.width, - widget->allocation.height); - - /* The contents of the widget can paint themselves */ - (*GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); - } - - return FALSE; -} - -static void -hildon_vvolumebar_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - requisition->height = MINIMUM_BAR_HEIGHT; - requisition->width = DEFAULT_BAR_WIDTH; -} - -static void -hildon_vvolumebar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - HildonVolumebarPrivate *priv; - - GtkAllocation range_allocation, button_allocation; - - priv = HILDON_VOLUMEBAR_GET_PRIVATE(widget); - g_assert (priv); - - /* Center the widget horizontally */ - if (allocation->width > DEFAULT_BAR_WIDTH) { - allocation->x += - (allocation->width - DEFAULT_BAR_WIDTH) / 2; - allocation->width = DEFAULT_BAR_WIDTH; - } - - GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); - - if (priv->volumebar && GTK_WIDGET_VISIBLE (priv->volumebar)) { - /* Allocate space for the slider */ - range_allocation.x = allocation->x; - range_allocation.y = allocation->y + DEFAULT_ENDING_SIZE; - - range_allocation.width = DEFAULT_BAR_WIDTH; - - if (priv->tbutton && GTK_WIDGET_VISIBLE (priv->tbutton)) - { - /* Leave room for the mute button */ - range_allocation.height = MAX (0, - allocation->height - - 2 * DEFAULT_ENDING_SIZE - - DEFAULT_VERTICAL_TBUTTON_HEIGHT - - VERTICAL_MUTE_GAP); - } - - else - { - range_allocation.height = MAX (0, - allocation->height - - 2 * DEFAULT_ENDING_SIZE); - } - - gtk_widget_size_allocate (GTK_WIDGET (priv->volumebar), - &range_allocation); - } - - if (priv->tbutton && GTK_WIDGET_VISIBLE (priv->tbutton)) { - /* Allocate space for the mute button */ - button_allocation.x = allocation->x + HORIZONTAL_MUTE_GAP; - button_allocation.y = allocation->y + allocation->height - - DEFAULT_VERTICAL_TBUTTON_HEIGHT - - VERTICAL_MUTE_GAP - 2 * DEFAULT_ENDING_SIZE; - button_allocation.width = DEFAULT_VERTICAL_TBUTTON_WIDTH; - button_allocation.height = DEFAULT_VERTICAL_TBUTTON_HEIGHT; - gtk_widget_size_allocate (GTK_WIDGET (priv->tbutton), - &button_allocation); - } -} diff --git a/hildon/hildon-vvolumebar.h b/hildon/hildon-vvolumebar.h deleted file mode 100644 index bf58c93..0000000 --- a/hildon/hildon-vvolumebar.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_VVOLUMEBAR_H__ -#define __HILDON_VVOLUMEBAR_H__ - -#include "hildon-volumebar.h" - -G_BEGIN_DECLS - -#define HILDON_TYPE_VVOLUMEBAR \ - (hildon_vvolumebar_get_type()) - -#define HILDON_VVOLUMEBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_VVOLUMEBAR, HildonVVolumebar)) - -#define HILDON_VVOLUMEBAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass),\ - HILDON_TYPE_VVOLUMEBAR, HildonVVolumebarClass)) - -#define HILDON_IS_VVOLUMEBAR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_VVOLUMEBAR)) - -#define HILDON_IS_VVOLUMEBAR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_VVOLUMEBAR)) - -#define HILDON_VVOLUMEBAR_GET_CLASS(obj) \ - ((HildonVVolumebarClass *) G_OBJECT_GET_CLASS(obj)) - -typedef struct _HildonVVolumebar HildonVVolumebar; - -typedef struct _HildonVVolumebarClass HildonVVolumebarClass; - -struct _HildonVVolumebar -{ - HildonVolumebar parent; -}; - -struct _HildonVVolumebarClass -{ - HildonVolumebarClass parent_class; -}; - -GType G_GNUC_CONST -hildon_vvolumebar_get_type (void); - -GtkWidget* -hildon_vvolumebar_new (void); - -G_END_DECLS - -#endif /* __HILDON_VVOLUMEBAR_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-weekday-picker-private.h b/hildon/hildon-weekday-picker-private.h deleted file mode 100644 index a97ca29..0000000 --- a/hildon/hildon-weekday-picker-private.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef __HILDON_WEEKDAY_PICKER_PRIVATE_H__ -#define __HILDON_WEEKDAY_PICKER_PRIVATE_H__ - -G_BEGIN_DECLS - -typedef struct _HildonWeekdayPickerPrivate HildonWeekdayPickerPrivate; - -#define HILDON_WEEKDAY_PICKER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - HILDON_TYPE_WEEKDAY_PICKER, HildonWeekdayPickerPrivate)); - -struct _HildonWeekdayPickerPrivate -{ - GtkWidget *buttons[8]; /* weekday buttons in show order */ - GtkWidget *day_order_buttons[8]; /* weekday buttons in glib day order */ -}; - -G_END_DECLS - -#endif /* __HILDON_WEEKDAY_PICKER_PRIVATE_H__ */ diff --git a/hildon/hildon-weekday-picker.c b/hildon/hildon-weekday-picker.c deleted file mode 100644 index d357c91..0000000 --- a/hildon/hildon-weekday-picker.c +++ /dev/null @@ -1,565 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -/** - * SECTION:hildon-weekday-picker - * @short_description: A widget for picking days on which a certain event - * should take place. - * @see_also: #HildonWeekdayPicker - * - * #HildonWeekdayPicker supports non-mutually exclusive selection of days of - * the week. Selected days of the week are shown with a pushed-in effect. - * - * #HildonWeekdayPicker is used where users are required to pick days on which - * a certain event should take place, for example, which days a Calendar event - * should be repeated on. It is used in Calendar in the Repeat dialog, in Tasks - * in the Repeat dialog and in the Email set-up wizard. - * - * <note> - * <para> - * #HildonWeekdayPicker has been deprecated since Hildon 2.2 and should not - * be used in newly written code. See - * <link linkend="hildon-migrating-date-widgets">Migrating Date Widgets</link> - * section to know how to migrate this deprecated widget. - * </para> - * </note> - * - * <example> - * <title>HildonWeekdayPicker example</title> - * <programlisting> - * gint i; - * HildonWeekdayPicker *picker = hildon_weekday_picker_new (); - * <!-- --> - * hildon_weekday_picker_set_day (picker, i); - * hildon_weekday_picker_unset_day (picker, i); - * hildon_weekday_picker_toggle_day (picker, i); - * hildon_weekday_picker_set_all (picker); - * <!-- --> - * hildon_weekday_picker_unset_all( picker ); - * </programlisting> - * </example> - * - */ - - /* GDate numbers days from 1 to 7 and G_DATE_MONDAY is 1st day. However - according to locale settings first day is sunday. To get around this - problem, we addjust GDate days numbering to be same as locale - numbering */ - -#undef HILDON_DISABLE_DEPRECATED - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <stdarg.h> -#include <sys/types.h> -#include <unistd.h> -#include <libintl.h> -#include <langinfo.h> -#include <time.h> -#include <gdk/gdkkeysyms.h> - -#include "hildon-weekday-picker.h" -#include "hildon-private.h" -#include "hildon-weekday-picker-private.h" - -static GtkContainerClass* parent_class; - -static void -hildon_weekday_picker_class_init (HildonWeekdayPickerClass *picker_class); - -static void -hildon_weekday_picker_init (HildonWeekdayPicker *picker); - -static void -hildon_weekday_picker_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gboolean -hildon_weekday_picker_focus (GtkWidget *widget, - GtkDirectionType direction); -static void -hildon_weekday_picker_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void -hildon_weekday_picker_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void -hildon_weekday_picker_destroy (GtkObject *self); - -static void -button_toggle (GtkToggleButton *togglebutton, - gpointer wpicker); - -enum -{ - SELECTION_CHANGED_SIGNAL, - LAST_SIGNAL -}; - -static guint signals [LAST_SIGNAL] = { 0 } ; - -/** - * hildon_weekday_picker_get_type: - * - * Initializes and returns the type of a hildon weekday picker. - * - * Returns: GType of #HildonWeekdayPicker - */ -GType G_GNUC_CONST -hildon_weekday_picker_get_type (void) -{ - static GType picker_type = 0; - - if (! picker_type) { - static const GTypeInfo picker_info = { - sizeof (HildonWeekdayPickerClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) hildon_weekday_picker_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (HildonWeekdayPicker), - 0, /* n_preallocs */ - (GInstanceInitFunc) hildon_weekday_picker_init, - }; - picker_type = g_type_register_static (GTK_TYPE_CONTAINER, - "HildonWeekdayPicker", - &picker_info, 0); - } - - return picker_type; -} - -static void -hildon_weekday_picker_class_init (HildonWeekdayPickerClass *picker_class) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (picker_class); - GtkContainerClass *container_class = GTK_CONTAINER_CLASS (picker_class); - GObjectClass *object_class = G_OBJECT_CLASS (picker_class); - - parent_class = g_type_class_peek_parent (picker_class); - - g_type_class_add_private (picker_class, - sizeof (HildonWeekdayPickerPrivate)); - - /* Override virtual methods */ - widget_class->size_request = hildon_weekday_picker_size_request; - widget_class->size_allocate = hildon_weekday_picker_size_allocate; - widget_class->focus = hildon_weekday_picker_focus; - container_class->forall = hildon_weekday_picker_forall; - GTK_OBJECT_CLASS (picker_class)->destroy = hildon_weekday_picker_destroy; - - /* Create a signal for reporting user actions */ - signals [SELECTION_CHANGED_SIGNAL] = g_signal_new ("selection_changed", - G_OBJECT_CLASS_TYPE - (object_class), - G_SIGNAL_RUN_LAST | - G_SIGNAL_ACTION, - G_STRUCT_OFFSET (HildonWeekdayPickerClass, selection_changed), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); -} - -static void -hildon_weekday_picker_init (HildonWeekdayPicker *picker) -{ - HildonWeekdayPickerPrivate *priv; - gint i, day; - - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - /* weekday indexes to be used with nl_langinfo. These are shifted - * by one for glib compability */ - int wdays[] = { - -1, /* 0 = invalid date */ - ABDAY_2, /* 1 = monday in glib */ - ABDAY_3, /* 2 = tuesday in glib */ - ABDAY_4, /* 3 = wednesday in glib */ - ABDAY_5, /* 4 = thursday in glib */ - ABDAY_6, /* 5 = friday in glib */ - ABDAY_7, /* 6 = saturday in glib */ - ABDAY_1 }; /* 7 = sunday in glib */ - GtkSizeGroup *sgroup; - - sgroup = gtk_size_group_new (GTK_SIZE_GROUP_BOTH); - - /* Check our first weekday */ - day = *nl_langinfo (_NL_TIME_FIRST_WEEKDAY); - - - /* Shift the days by one. This is done because GDateWeekday - * starts with Monday(1) and langinfo's first day is Sunday */ - day--; - - if (day < 1) - day = 7; - - /* Initialize and pack day buttons */ - for (i = 1; i <= 7; i++) { - priv->buttons [i] = - gtk_toggle_button_new_with_label (nl_langinfo (wdays[day])); - priv->day_order_buttons [day] = priv->buttons [i]; - day++; - - if (day > 7) - day = 1; - - g_signal_connect (GTK_WIDGET (priv->buttons [i]), - "toggled", G_CALLBACK (button_toggle), picker); - - gtk_size_group_add_widget (sgroup, priv->buttons [i]); - - gtk_widget_set_parent (priv->buttons [i], GTK_WIDGET (picker)); - gtk_widget_show (priv->buttons[i]); - } - - GTK_WIDGET_SET_FLAGS (picker, GTK_NO_WINDOW); - - g_object_unref (sgroup); -} - -/** - * hildon_weekday_picker_new: - * - * Creates a new #HildonWeekdayPicker. - * - * Returns: pointer to a new #HildonWeekdayPicker widget. - */ -GtkWidget* -hildon_weekday_picker_new (void) -{ - return g_object_new (HILDON_TYPE_WEEKDAY_PICKER, NULL); -} - -static void -hildon_weekday_picker_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - HildonWeekdayPicker *picker; - HildonWeekdayPickerPrivate *priv; - gint i; - - g_assert (container); - g_assert (callback); - - picker = HILDON_WEEKDAY_PICKER (container); - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - /* We only have internal children */ - if (! include_internals) - return; - - /* Activate callback for each day button */ - for (i = 1; i <= 7; ++i) { - (*callback) (priv->buttons [i], callback_data); - } -} - -static void -hildon_weekday_picker_destroy (GtkObject *self) -{ - HildonWeekdayPickerPrivate *priv; - gint i; - - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (self); - g_assert (priv); - - /* Destroy internal children... */ - for (i = 1; i <= 7; ++i) { - if (priv->buttons [i]) - { - gtk_widget_unparent (priv->buttons [i]); - priv->buttons [i] = NULL; - } - } - - /* ... and chain to parent. */ - if (GTK_OBJECT_CLASS (parent_class)->destroy) - GTK_OBJECT_CLASS (parent_class)->destroy (self); - -} - -static void -hildon_weekday_picker_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - HildonWeekdayPicker *picker; - HildonWeekdayPickerPrivate *priv; - gint i; - GtkRequisition req; - - picker = HILDON_WEEKDAY_PICKER (widget); - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - requisition->width = 0; - requisition->height = 0; - - /* Request an area that is as wide as all of the buttons - together and tall enough to hold heightest button */ - for (i = 1; i <= 7; ++i) { - gtk_widget_size_request (priv->buttons [i], &req); - requisition->width += req.width; - if (req.height > requisition->height) - requisition->height = req.height; - - } -} - -static void -hildon_weekday_picker_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - HildonWeekdayPicker *picker; - HildonWeekdayPickerPrivate *priv; - gint i; - GtkAllocation alloc; - GtkRequisition child_requisition; - gint header_x; - guint sval; - GtkTextDirection direction; - - g_assert (widget); - g_assert (allocation); - - /* Check orientation */ - direction = gtk_widget_get_direction (widget); - - picker = HILDON_WEEKDAY_PICKER (widget); - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - header_x = allocation->x; - widget->allocation = *allocation; - - if (direction == GTK_TEXT_DIR_LTR || direction == GTK_TEXT_DIR_NONE) - sval = 1; - else - sval = 7; - - /* Allocate day buttons side by side honouring the text direction */ - for (i = 1; i <= 7; ++i) { - gtk_widget_get_child_requisition (priv->buttons[sval], &child_requisition); - - alloc.x = header_x; - alloc.y = allocation->y; - alloc.width = child_requisition.width; - alloc.height = child_requisition.height; - header_x += alloc.width; - gtk_widget_size_allocate (priv->buttons [sval], &alloc); - if (direction == GTK_TEXT_DIR_RTL) - sval--; - else - sval++; - } -} - -static gboolean -hildon_weekday_picker_focus (GtkWidget *widget, - GtkDirectionType direction) -{ - gboolean retval; - GtkDirectionType effective_direction; - - g_assert (HILDON_IS_WEEKDAY_PICKER (widget)); - - retval = hildon_private_composite_focus (widget, direction, &effective_direction); - - if (retval == TRUE) - return GTK_WIDGET_CLASS (parent_class)->focus (widget, effective_direction); - else - return FALSE; -} - -static void -button_toggle (GtkToggleButton *button, - gpointer wpicker) -{ - HildonWeekdayPicker *picker; - HildonWeekdayPickerPrivate *priv; - gint i; - - g_assert(button); - g_assert(wpicker); - - picker = HILDON_WEEKDAY_PICKER (wpicker); - g_assert (picker); - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - for (i = 1; i <= 7; ++i) { - if (GTK_WIDGET (button) == priv->day_order_buttons [i]) { - g_signal_emit (GTK_WIDGET (picker), - signals [SELECTION_CHANGED_SIGNAL], 0, i); - break; - } - } -} - -/** - * hildon_weekday_picker_set_day: - * @picker: the #HildonWeekdayPicker widget - * @day: day to be set active - * - * Sets specified weekday active. - */ -void -hildon_weekday_picker_set_day (HildonWeekdayPicker *picker, - GDateWeekday day) -{ - HildonWeekdayPickerPrivate *priv; - - g_return_if_fail (HILDON_IS_WEEKDAY_PICKER (picker)); - g_return_if_fail (g_date_valid_weekday(day)); - - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON - (priv->day_order_buttons[day]), TRUE); -} - -/** - * hildon_weekday_picker_unset_day: - * @picker: the #HildonWeekdayPicker widget - * @day: day to be set inactive - * - * Unselect specified weekday. - */ -void -hildon_weekday_picker_unset_day (HildonWeekdayPicker *picker, - GDateWeekday day) -{ - HildonWeekdayPickerPrivate *priv; - - g_return_if_fail (HILDON_IS_WEEKDAY_PICKER (picker)); - g_return_if_fail (g_date_valid_weekday (day)); - - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON - (priv->day_order_buttons [day]), FALSE); -} - -/** - * hildon_weekday_picker_toggle_day: - * @picker: the #HildonWeekdayPicker widget - * @day: day to be toggled - * - * Toggles current status of the specified weekday. - */ -void -hildon_weekday_picker_toggle_day (HildonWeekdayPicker *picker, - GDateWeekday day) -{ - HildonWeekdayPickerPrivate *priv; - - g_return_if_fail (HILDON_IS_WEEKDAY_PICKER (picker)); - g_return_if_fail (g_date_valid_weekday (day)); - - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (priv->day_order_buttons [day]), - ! gtk_toggle_button_get_active( - GTK_TOGGLE_BUTTON (priv->day_order_buttons[day]))); -} - -/** - * hildon_weekday_picker_set_all: - * @picker: the #HildonWeekdayPicker widget - * - * Sets all weekdays active. - */ -void -hildon_weekday_picker_set_all (HildonWeekdayPicker *picker) -{ - HildonWeekdayPickerPrivate *priv; - gint i; - - g_return_if_fail (HILDON_IS_WEEKDAY_PICKER (picker)); - - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - for (i = 1; i <= 7; i++) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->buttons [i]), TRUE); -} - -/** - * hildon_weekday_picker_unset_all: - * @picker: the #HildonWeekdayPicker widget - * - * Sets all weekdays inactive. - */ -void -hildon_weekday_picker_unset_all (HildonWeekdayPicker *picker) -{ - HildonWeekdayPickerPrivate *priv; - gint i; - - g_return_if_fail (HILDON_IS_WEEKDAY_PICKER (picker)); - - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (priv); - - for (i = 1; i <= 7; i++) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->buttons [i]), FALSE); -} - -/** - * hildon_weekday_picker_isset_day: - * @picker: the #HildonWeekdayPicker widget - * @day: day to be checked. - * - * Checks if the specified weekday is set active. - * - * Returns: TRUE if the day is set, FALSE if the day is not set - */ -gboolean -hildon_weekday_picker_isset_day (HildonWeekdayPicker *picker, - GDateWeekday day) -{ - HildonWeekdayPickerPrivate *priv; - - g_return_val_if_fail (HILDON_IS_WEEKDAY_PICKER (picker), FALSE); - g_return_val_if_fail (g_date_valid_weekday (day), FALSE); - - priv = HILDON_WEEKDAY_PICKER_GET_PRIVATE (picker); - g_assert (picker); - - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->day_order_buttons[day])); -} - diff --git a/hildon/hildon-weekday-picker.h b/hildon/hildon-weekday-picker.h deleted file mode 100644 index bf7b833..0000000 --- a/hildon/hildon-weekday-picker.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is a part of hildon - * - * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. - * - * Contact: Rodrigo Novo <rodrigo.novo@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef HILDON_DISABLE_DEPRECATED - -#ifndef __HILDON_WEEKDAY_PICKER_H__ -#define __HILDON_WEEKDAY_PICKER_H__ - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -typedef struct _HildonWeekdayPicker HildonWeekdayPicker; - -typedef struct _HildonWeekdayPickerClass HildonWeekdayPickerClass; - -#define HILDON_TYPE_WEEKDAY_PICKER \ - (hildon_weekday_picker_get_type()) - -#define HILDON_WEEKDAY_PICKER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST (obj, \ - HILDON_TYPE_WEEKDAY_PICKER, \ - HildonWeekdayPicker)) - -#define HILDON_WEEKDAY_PICKER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - HILDON_TYPE_WEEKDAY_PICKER, HildonWeekdayPickerClass)) - -#define HILDON_IS_WEEKDAY_PICKER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE (obj, HILDON_TYPE_WEEKDAY_PICKER)) - -#define HILDON_IS_WEEKDAY_PICKER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_WEEKDAY_PICKER)) - -#define HILDON_WEEKDAY_PICKER_GET_CLASS(obj) \ - ((HildonWeekdayPickerClass *) G_OBJECT_GET_CLASS(obj)) - -struct _HildonWeekdayPicker -{ - GtkContainer parent; -}; - -struct _HildonWeekdayPickerClass -{ - GtkContainerClass parent_class; - - void (*selection_changed) (HildonWeekdayPicker *self); -}; - -GType G_GNUC_CONST -hildon_weekday_picker_get_type (void); - -GtkWidget* -hildon_weekday_picker_new (void); - -void -hildon_weekday_picker_set_day (HildonWeekdayPicker *picker, - GDateWeekday day); - -void -hildon_weekday_picker_unset_day (HildonWeekdayPicker *picker, - GDateWeekday day); - -void -hildon_weekday_picker_toggle_day (HildonWeekdayPicker *picker, - GDateWeekday day); - -void -hildon_weekday_picker_set_all (HildonWeekdayPicker *picker); - -void -hildon_weekday_picker_unset_all (HildonWeekdayPicker *picker); - -gboolean -hildon_weekday_picker_isset_day (HildonWeekdayPicker * picker, - GDateWeekday day); - -G_END_DECLS - -#endif /* __HILDON_WEEKDAY_PICKER_H__ */ - -#endif /* HILDON_DISABLE_DEPRECATED */ diff --git a/hildon/hildon-window-private.h b/hildon/hildon-window-private.h index c9f3368..fb6e5d6 100644 --- a/hildon/hildon-window-private.h +++ b/hildon/hildon-window-private.h @@ -49,7 +49,6 @@ struct _HildonWindowPrivate guint fullscreen; guint is_topmost; - guint escape_timeout; gint visible_toolbars; gint previous_vbox_y; diff --git a/hildon/hildon-window.c b/hildon/hildon-window.c index 8786d5d..01d20c3 100644 --- a/hildon/hildon-window.c +++ b/hildon/hildon-window.c @@ -77,8 +77,6 @@ * </example> */ -#undef HILDON_DISABLE_DEPRECATED - #include <memory.h> #include <string.h> #include <strings.h> @@ -190,14 +188,8 @@ hildon_window_key_press_event (GtkWidget *widget, GdkEventKey *event); static gboolean -hildon_window_key_release_event (GtkWidget *widget, - GdkEventKey *event); -static gboolean hildon_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event); -static gboolean -hildon_window_focus_out_event (GtkWidget *widget, - GdkEventFocus *event); static void hildon_window_notify (GObject *gobject, @@ -216,9 +208,6 @@ hildon_window_toggle_menu_real (HildonWindow * self, guint button, guint32 time); -static gboolean -hildon_window_escape_timeout (gpointer data); - static GdkFilterReturn hildon_window_event_filter (GdkXEvent *xevent, GdkEvent *event, @@ -277,9 +266,7 @@ hildon_window_class_init (HildonWindowClass * window_clas widget_class->realize = hildon_window_realize; widget_class->unrealize = hildon_window_unrealize; widget_class->key_press_event = hildon_window_key_press_event; - widget_class->key_release_event = hildon_window_key_release_event; widget_class->window_state_event = hildon_window_window_state_event; - widget_class->focus_out_event = hildon_window_focus_out_event; widget_class->map = hildon_window_map; widget_class->unmap = hildon_window_unmap; @@ -354,7 +341,6 @@ hildon_window_init (HildonWindow *self) priv->is_topmost = FALSE; priv->borders = NULL; priv->toolbar_borders = NULL; - priv->escape_timeout = 0; priv->markup = NULL; priv->fullscreen = FALSE; @@ -374,11 +360,6 @@ hildon_window_finalize (GObject * obj_self) g_free (priv->markup); - if (priv->escape_timeout) { - g_source_remove (priv->escape_timeout); - priv->escape_timeout = 0; - } - if (priv->borders) gtk_border_free (priv->borders); @@ -1080,25 +1061,6 @@ hildon_window_event_filter (GdkXEvent *xevent, hildon_window_toggle_menu (HILDON_WINDOW ( data ), cm->data.l[2], cm->data.l[0]); return GDK_FILTER_REMOVE; } - /* opera hack clipboard client message */ - else if (xclient_message_type_check (cm, "_HILDON_IM_CLIPBOARD_COPY")) - { - g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation", - HILDON_WINDOW_CO_COPY); - return GDK_FILTER_REMOVE; - } - else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_CUT")) - { - g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation", - HILDON_WINDOW_CO_CUT); - return GDK_FILTER_REMOVE; - } - else if (xclient_message_type_check(cm, "_HILDON_IM_CLIPBOARD_PASTE")) - { - g_signal_emit_by_name(G_OBJECT(data), "clipboard_operation", - HILDON_WINDOW_CO_PASTE); - return GDK_FILTER_REMOVE; - } } if (eventti->type == PropertyNotify) @@ -1137,43 +1099,11 @@ hildon_window_key_press_event (GtkWidget *widget, if (hildon_window_toggle_menu (HILDON_WINDOW (widget), 0, GDK_CURRENT_TIME)) return TRUE; break; - case HILDON_HARDKEY_ESC: - if (!priv->escape_timeout) - { - priv->escape_timeout = gdk_threads_add_timeout - (HILDON_WINDOW_LONG_PRESS_TIME, - hildon_window_escape_timeout, widget); - } - break; } return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_press_event (widget, event); } -static gboolean -hildon_window_key_release_event (GtkWidget *widget, - GdkEventKey *event) -{ - HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget); - - g_return_val_if_fail (HILDON_IS_WINDOW (widget), FALSE); - g_assert (priv); - - switch (event->keyval) - { - case HILDON_HARDKEY_ESC: - if (priv->escape_timeout) - { - g_source_remove (priv->escape_timeout); - priv->escape_timeout = 0; - } - break; - } - - return GTK_WIDGET_CLASS (hildon_window_parent_class)->key_release_event (widget, event); - -} - /* * We keep track of the window state changes, because the drawing * (borders) differs whether we are in fullscreen mode or not @@ -1200,25 +1130,6 @@ hildon_window_window_state_event (GtkWidget *widget, } } -/* - * If the window lost focus while the user started to press the ESC key, we - * won't get the release event. We need to stop the timeout. - */ -static gboolean -hildon_window_focus_out_event (GtkWidget *widget, - GdkEventFocus *event) -{ - HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (widget); - - if (priv->escape_timeout) - { - g_source_remove (priv->escape_timeout); - priv->escape_timeout = 0; - } - - return GTK_WIDGET_CLASS (hildon_window_parent_class)->focus_out_event (widget, event); -} - static void set_legacy_menu_type (GtkMenu *menu, gboolean set) @@ -1678,32 +1589,6 @@ hildon_window_toggle_menu_real (HildonWindow * self, return retvalue; } -/* - * If the ESC key was not released when the timeout expires, - * close the window - */ -static gboolean -hildon_window_escape_timeout (gpointer data) -{ - HildonWindowPrivate *priv = HILDON_WINDOW_GET_PRIVATE (data); - GdkEvent *event; - - g_assert (priv); - - /* Send fake event, simulation a situation that user - pressed 'x' from the corner */ - event = gdk_event_new(GDK_DELETE); - ((GdkEventAny *)event)->window = GDK_WINDOW (g_object_ref (GTK_WIDGET(data)->window)); - gtk_main_do_event(event); - - /* That unrefs the window, so we're reffing it above */ - gdk_event_free(event); - - priv->escape_timeout = 0; - - return FALSE; -} - /** * hildon_window_new: * @@ -1919,23 +1804,6 @@ hildon_window_get_main_menu (HildonWindow * self) return priv->menu; } -/** - * hildon_window_get_menu: - * @self: a #HildonWindow - * - * Gets the #GtkMenu assigned to @self - * - * Return value: a #GtkMenu - * - * Deprecated: In Hildon 2.2 this function has been renamed to - * hildon_window_get_main_menu() for consistency - **/ -GtkMenu* -hildon_window_get_menu (HildonWindow * self) -{ - return hildon_window_get_main_menu (self); -} - /* Since we've been asking developers to call gtk_window_add_accel_group() * themselves, do not trigger criticals by trying it again. */ @@ -2024,40 +1892,6 @@ hildon_window_set_main_menu (HildonWindow* self, } /** - * hildon_window_set_menu: - * @self: A #HildonWindow - * @menu: The #GtkMenu to be used for this #HildonWindow - * - * Sets the menu to be used for this window. This menu overrides - * a program-wide menu that may have been set with - * hildon_program_set_common_menu(). Pass %NULL to remove the current - * menu. HildonWindow takes ownership of the passed menu and you're - * not supposed to free it yourself anymore. - * - * Note: hildon_window_set_menu() calls gtk_widget_show_all() for the - * #GtkMenu. To pass control about visibility to the application - * developer, hildon_window_set_main_menu() was introduced, which - * doesn't do this. - * - * Deprecated: Hildon 2.2: use hildon_window_set_main_menu() - **/ -void -hildon_window_set_menu (HildonWindow *self, - GtkMenu *menu) -{ - HildonWindowPrivate *priv; - - g_return_if_fail (HILDON_IS_WINDOW (self)); - - hildon_window_set_main_menu (self, menu); - - priv = HILDON_WINDOW_GET_PRIVATE (self); - - if (priv->menu != NULL) - gtk_widget_show_all (GTK_WIDGET (priv->menu)); -} - -/** * hildon_window_get_is_topmost: * @self: A #HildonWindow * diff --git a/hildon/hildon-window.h b/hildon/hildon-window.h index dccefe3..4b684d8 100644 --- a/hildon/hildon-window.h +++ b/hildon/hildon-window.h @@ -31,19 +31,6 @@ G_BEGIN_DECLS -#ifndef HILDON_DISABLE_DEPRECATED -/** - * HILDON_WINDOW_LONG_PRESS_TIME: - * - * Time (in miliseconds) after which a hardware key press is - * considered a long press. - * - * Deprecated: Hildon 2.2: this value is only meant to be used - * internally by Hildon. - */ -#define HILDON_WINDOW_LONG_PRESS_TIME 800 -#endif - #define HILDON_TYPE_WINDOW \ (hildon_window_get_type()) @@ -68,21 +55,6 @@ typedef struct _HildonWindow HildonWindow; typedef struct _HildonWindowClass HildonWindowClass; -#ifndef HILDON_DISABLE_DEPRECATED -/** - * HildonWindowClipboardOperation: - * - * Deprecated: Hildon 2.2: this value is only meant to be used - * internally by Hildon - */ -typedef enum -{ - HILDON_WINDOW_CO_COPY, - HILDON_WINDOW_CO_CUT, - HILDON_WINDOW_CO_PASTE -} HildonWindowClipboardOperation; -#endif /* HILDON_DISABLE_DEPRECATED */ - struct _HildonWindow { GtkWindow parent; @@ -124,15 +96,6 @@ hildon_window_set_app_menu (HildonWindow *self, HildonAppMenu * hildon_window_get_app_menu (HildonWindow *self); -#ifndef HILDON_DISABLE_DEPRECATED -void -hildon_window_set_menu (HildonWindow *self, - GtkMenu *menu); - -GtkMenu* -hildon_window_get_menu (HildonWindow *self); -#endif - void hildon_window_add_toolbar (HildonWindow *self, GtkToolbar *toolbar); diff --git a/hildon/hildon.h b/hildon/hildon.h index 84cbf7a..71d0e32 100644 --- a/hildon/hildon.h +++ b/hildon/hildon.h @@ -27,34 +27,16 @@ #include "hildon-version.h" #include "hildon-banner.h" -#include "hildon-calendar-popup.h" #include "hildon-caption.h" -#include "hildon-code-dialog.h" -#include "hildon-color-button.h" -#include "hildon-color-chooser-dialog.h" -#include "hildon-color-chooser.h" -#include "hildon-controlbar.h" -#include "hildon-date-editor.h" #include "hildon-defines.h" #include "hildon-helper.h" #include "hildon-enum-types.h" #include "hildon-find-toolbar.h" #include "hildon-edit-toolbar.h" -#include "hildon-font-selection-dialog.h" -#include "hildon-get-password-dialog.h" -#include "hildon-hvolumebar.h" -#include "hildon-login-dialog.h" #include "hildon-marshalers.h" #include "hildon-note.h" -#include "hildon-number-editor.h" #include "hildon-program.h" -#include "hildon-range-editor.h" -#include "hildon-seekbar.h" -#include "hildon-set-password-dialog.h" -#include "hildon-sort-dialog.h" #include "hildon-sound.h" -#include "hildon-time-editor.h" -#include "hildon-time-picker.h" #include "hildon-date-selector.h" #include "hildon-time-selector.h" #include "hildon-touch-selector.h" @@ -63,17 +45,11 @@ #include "hildon-picker-button.h" #include "hildon-date-button.h" #include "hildon-time-button.h" -#include "hildon-volumebar-range.h" -#include "hildon-volumebar.h" -#include "hildon-vvolumebar.h" -#include "hildon-weekday-picker.h" #include "hildon-window.h" #include "hildon-stackable-window.h" #include "hildon-window-stack.h" #include "hildon-animation-actor.h" #include "hildon-wizard-dialog.h" -#include "hildon-calendar.h" -#include "hildon-bread-crumb-trail.h" #include "hildon-pannable-area.h" #include "hildon-entry.h" #include "hildon-text-view.h" @@ -81,7 +57,6 @@ #include "hildon-button.h" #include "hildon-check-button.h" #include "hildon-gtk.h" -#include "hildon-dialog.h" #include "hildon-main.h" #include "hildon-live-search.h" #include "hildon-stock.h" diff --git a/tests/Makefile.am b/tests/Makefile.am index 8994907..a933b09 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -18,30 +18,7 @@ tests = check_test.c \ check-hildon-program.c \ check-hildon-picker-button.c - -DEPRECATED_TESTS = check-hildon-range-editor.c \ - check-hildon-date-editor.c \ - check-hildon-time-editor.c \ - check-hildon-weekday-picker.c \ - check-hildon-controlbar.c \ - check-hildon-seekbar.c \ - check-hildon-time-picker.c \ - check-hildon-number-editor.c \ - check-hildon-calendar-popup.c \ - check-hildon-code-dialog.c \ - check-hildon-sort-dialog.c \ - check-hildon-volumebar.c \ - check-hildon-volumebar-range.c \ - check-hildon-font-selection-dialog.c \ - check-hildon-color-button.c \ - check-hildon-color-chooser.c - -if HILDON_DISABLE_DEPRECATED check_test_SOURCES = $(tests) -else -check_test_SOURCES = $(tests) \ - $(DEPRECATED_TESTS) -endif check_test_SOURCES += test_suites.h \ check_utils.h diff --git a/tests/check-hildon-banner.c b/tests/check-hildon-banner.c index ed3ee42..cde0ae1 100644 --- a/tests/check-hildon-banner.c +++ b/tests/check-hildon-banner.c @@ -21,8 +21,6 @@ * 02110-1301 USA * */ -#ifndef HILDON_DISABLE_DEPRECATED - #include <stdlib.h> #include <check.h> #include <gtk/gtkmain.h> @@ -244,4 +242,3 @@ Suite *create_hildon_banner_suite() return s; } -#endif diff --git a/tests/check-hildon-calendar-popup.c b/tests/check-hildon-calendar-popup.c deleted file mode 100644 index 50f03d1..0000000 --- a/tests/check-hildon-calendar-popup.c +++ /dev/null @@ -1,506 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <time.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-calendar-popup.h> - -/* -------------------- Fixtures -------------------- */ - -static HildonCalendarPopup *calendar = NULL; - -static void -fx_setup_default_calendar() -{ - int argc = 0; - - gtk_init(&argc, NULL); - - calendar = HILDON_CALENDAR_POPUP(hildon_calendar_popup_new(NULL, 2006, 4, 10)); - - show_test_window(GTK_WIDGET(calendar)); - - /* Check calendar object has been created properly */ - fail_if(!HILDON_IS_CALENDAR_POPUP(calendar), - "hildon-calendar-popup: Creation failed."); -} - -static void -fx_teardown_default_calendar() -{ - - gtk_widget_destroy(GTK_WIDGET(calendar)); - -} - -/* -------------------- Test cases -------------------- */ - -/* ------ Test case for get/set_date ----- */ - -/** - * Purpose: Check regular values for dates - * Cases considered: - * - Set and get date 30/03/1981 - */ -START_TEST (test_set_get_date_regular) -{ - guint year, month, day; - guint ret_year, ret_month, ret_day; - - /* Test1: set a valid date like 30/03/1981 */ - year = 1981; - month = 3; - day = 30; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(year != ret_year || month != ret_month || day != ret_day, - "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned date %u/%u/%u", - year, month, day, ret_year, ret_month, ret_day); - -} -END_TEST - -/** - * Purpose: Check limit values for dates - * Cases considered: - * - Set and get year to max-year property - * - Set and get year to min-year property - * - Set and get month to 12 - * - Set and get month to 1 - * - Set and get day to 31 (March) - * - Set and get day to 30 (April) - * - Set and get day to 29 (February 2004) - * - Set and get day to 28 (February 2006) - * - Set and get day to 1 - * - Set and get maximum allowed date (according to max-year property). - * - Set and get minimum allowed date (according to min-year property). - */ -START_TEST (test_set_get_date_limits) -{ - GValue value = {0, }; - guint year, month, day; - guint ret_year, ret_month, ret_day; - guint max_year, min_year; - - g_value_init(&value, G_TYPE_UINT); - - /* Test1: Test year maximum limit */ - max_year = 2050; - g_value_set_uint (&value, max_year); - g_object_set_property (G_OBJECT (calendar), "max-year", &value); - year = max_year; - month = 3; - day = 30; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(year != ret_year, - "hildon-calendar-popup: Set date to %u/%u/%u, with maximum year set to %u, but get date returned year %u", - year, month, day, max_year, ret_year); - - /* Test2: Test year minimum limit */ - min_year = 2000; - g_value_set_uint (&value, min_year); - g_object_set_property (G_OBJECT (calendar), "min-year", &value); - year = min_year; - month = 3; - day = 30; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(year != ret_year, - "hildon-calendar-popup: Set date to %u/%u/%u, with minimum year set to %u, but get date returned year %u", - year, month, day, min_year, ret_year); - - /* Test3: Test month minimum limit */ - year = 2006; - month = 1; - day = 10; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(month != ret_month, - "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned month %u", - year, month, day, ret_month); - - /* Test4: Test month maximum limit */ - year = 2006; - month = 12; - day = 10; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(month != ret_month, - "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned month %u", - year, month, day, ret_month); - - /* Test5: Test day maximum limit */ - - /* 31 */ - year = 2006; - month = 3; - day = 31; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(day != ret_day, - "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u", - year, month, day, ret_day); - - /* 30 */ - year = 2006; - month = 4; - day = 30; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(day != ret_day, - "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u", - year, month, day, ret_day); - - /* February 28th */ - year = 2006; - month = 2; - day = 28; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(day != ret_day, - "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u", - year, month, day, ret_day); - - /* February 29th */ - year = 2004; - month = 2; - day = 29; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(day != ret_day, - "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u", - year, month, day, ret_day); - - /* Test6: Test day minimum limit */ - year = 2006; - month = 2; - day = 1; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(day != ret_day, - "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u", - year, month, day, ret_day); - - /* Test7: Test maximum allowed date */ - max_year = 2050; - g_value_set_uint (&value, max_year); - g_object_set_property (G_OBJECT (calendar), "max-year", &value); - year = max_year; - month = 12; - day = 31; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(year != ret_year, - "hildon-calendar-popup: Set date to %u/%u/%u, with maximum year set to %u, but get date returned date %u/%u/%u", - year, month, day, max_year, ret_year, ret_month, ret_day); - - /* Test8: Test minimum allowed date */ - min_year = 2000; - g_value_set_uint (&value, min_year); - g_object_set_property (G_OBJECT (calendar), "min-year", &value); - year = min_year; - month = 1; - day = 1; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(year != ret_year, - "hildon-calendar-popup: Set date to %u/%u/%u, with minimum year set to %u, but get date returned date %u/%u/%u", - year, month, day, min_year, ret_year, ret_month, ret_day); -} -END_TEST - -/** - * Purpose: Check invalid values for dates - * Cases considered: - * - Set and get year above max-year property - * - Set and get year under min-year property - * - Set and get month to 13 - * - Set and get month to 0 - * - Set and get day to 32 (March) - * - Set and get day to 31 (April) - * - Set and get day to 30 (February 2004) - * - Set and get day to 29 (February 2006) - * - Set and get day to 0 - * - Set and get above maximum allowed date (according to max-year property). - * - Set and get under minimum allowed date (according to min-year property). - * - Set and get date using NULL calendar object - */ -START_TEST (test_set_get_date_invalid) -{ - GValue value = {0, }; - guint year, month, day; - guint valid_year, valid_month, valid_day; - guint current_year, current_month, current_day; - guint ret_year, ret_month, ret_day; - guint max_year, min_year; - GDate date; - - g_value_init(&value, G_TYPE_UINT); - - /* Test 1: Test under minimum year limit */ - min_year = 2000; - g_value_set_uint (&value, min_year); - g_object_set_property (G_OBJECT (calendar), "min-year", &value); - year = min_year - 1; - month = 3; - day = 30; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if(min_year != ret_year, - "hildon-calendar-popup: Set date to %u/%u/%u, with minimum year set to %u, but get date returned year = %u != %u", - year, month, day, min_year, ret_year, min_year); - - /* Test 2: Test above maximum month limit */ - valid_year = 2006; - valid_month = 10; - valid_day = 5; - hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day); - year = 2010; - month = 13; - day = 12; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - - /* Gets the curret date */ - g_date_clear(&date, 1); - g_date_set_time(&date, time(NULL)); - - current_day = g_date_get_day(&date); - current_month = g_date_get_month(&date); - current_year = g_date_get_year(&date); - - fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day), - "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u", - valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day); - - - /* Test 3: Test under minimum month limit */ - valid_year = 2006; - valid_month = 2; - valid_day = 15; - hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day); - year = 2010; - month = 0; - day = 10; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - - /* Gets the curret date */ - g_date_clear(&date, 1); - g_date_set_time(&date, time(NULL)); - - current_day = g_date_get_day(&date); - current_month = g_date_get_month(&date); - current_year = g_date_get_year(&date); - - fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day), - "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u", - valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day); - - - /* Test 4: Test above maximum day limit */ - - /* 31 */ - valid_year = 2005; - valid_month = 2; - valid_day = 15; - hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day); - year = 2006; - month = 3; - day = 32; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - - /* Gets the curret date */ - g_date_clear(&date, 1); - g_date_set_time(&date, time(NULL)); - - current_day = g_date_get_day(&date); - current_month = g_date_get_month(&date); - current_year = g_date_get_year(&date); - - fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day), - "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u", - valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day); - - - /* 30 */ - valid_year = 2005; - valid_month = 2; - valid_day = 15; - hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day); - year = 2006; - month = 4; - day = 31; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - - /* Gets the curret date */ - g_date_clear(&date, 1); - g_date_set_time(&date, time(NULL)); - - current_day = g_date_get_day(&date); - current_month = g_date_get_month(&date); - current_year = g_date_get_year(&date); - - fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day), - "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u", - valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day); - - /* February 28th */ - valid_year = 2005; - valid_month = 2; - valid_day = 15; - hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day); - year = 2006; - month = 2; - day = 29; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - - /* Gets the curret date */ - g_date_clear(&date, 1); - g_date_set_time(&date, time(NULL)); - - current_day = g_date_get_day(&date); - current_month = g_date_get_month(&date); - current_year = g_date_get_year(&date); - - fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day), - "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u", - valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day); - - - /* February 29th */ - valid_year = 2005; - valid_month = 2; - valid_day = 15; - hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day); - year = 2004; - month = 2; - day = 30; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - - /* Gets the curret date */ - g_date_clear(&date, 1); - g_date_set_time(&date, time(NULL)); - - current_day = g_date_get_day(&date); - current_month = g_date_get_month(&date); - current_year = g_date_get_year(&date); - - fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day), - "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u", - valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day); - - /* Test5: Test day minimum limit */ - valid_year = 2005; - valid_month = 2; - valid_day = 15; - hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day); - year = 2006; - month = 2; - day = 0; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - - /* Gets the curret date */ - g_date_clear(&date, 1); - g_date_set_time(&date, time(NULL)); - - current_day = g_date_get_day(&date); - current_month = g_date_get_month(&date); - current_year = g_date_get_year(&date); - - fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day), - "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u", - valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day); - - /* Test6: Test above maximum allowed date */ - max_year = 2050; - g_value_set_uint (&value, max_year); - g_object_set_property (G_OBJECT (calendar), "max-year", &value); - valid_year = 2005; - valid_month = 2; - valid_day = 15; - hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day); - year = max_year + 1; - month = 1; - day = 1; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if((max_year != ret_year) || (month != ret_month) || (day != ret_day), - "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, with maximum year set to %u, but get date returned %u/%u/%u instead of %u/%u/%u", - valid_year, valid_month, valid_day, year, month, day, max_year, ret_year, ret_month, ret_day, max_year, month, day); - - /* Test7: Test minimum allowed date */ - min_year = 2000; - g_value_set_uint (&value, min_year); - g_object_set_property (G_OBJECT (calendar), "min-year", &value); - valid_year = 2005; - valid_month = 2; - valid_day = 15; - hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day); - year = min_year - 1; - month = 12; - day = 31; - hildon_calendar_popup_set_date(calendar, year, month, day); - hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day); - fail_if((min_year != ret_year) || (month != ret_month) || (day != ret_day), - "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, with minimum year set to %u, but get date returned %u/%u/%u instead of %u/%u/%u", - valid_year, valid_month, valid_day, year, month, day, min_year, ret_year, ret_month, ret_day, min_year, month, day); - - /* Test8: Set and get date with NULL calendar objects */ - hildon_calendar_popup_set_date(NULL, 2006, 10, 15); - hildon_calendar_popup_get_date(NULL, &year, &month, &day); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_calendar_popup_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonCalendarPopup"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_get_date"); - - /* Create test case for set_date and get_date and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_calendar, fx_teardown_default_calendar); - tcase_add_test(tc1, test_set_get_date_regular); - tcase_add_test(tc1, test_set_get_date_limits); - tcase_add_test(tc1, test_set_get_date_invalid); - suite_add_tcase (s, tc1); - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-code-dialog.c b/tests/check-hildon-code-dialog.c deleted file mode 100644 index aea147e..0000000 --- a/tests/check-hildon-code-dialog.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkhbox.h> -#include <glib/gprintf.h> -#include <string.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-code-dialog.h> - -/* -------------------- Fixtures -------------------- */ - -static HildonCodeDialog *code_dialog = NULL; - -static void -fx_setup_default_code_dialog() -{ - int argc = 0; - gtk_init(&argc, NULL); - - code_dialog = HILDON_CODE_DIALOG(hildon_code_dialog_new()); - /* Check code_dialog object has been created properly */ - fail_if(!HILDON_IS_CODE_DIALOG(code_dialog), - "hildon-code-dialog: Creation failed."); - - show_test_window(GTK_WIDGET(code_dialog)); - -} - -static void -fx_teardown_default_code_dialog() -{ - - /* Destroy the dialog */ - gtk_widget_destroy (GTK_WIDGET (code_dialog)); - -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for get_code -----*/ -/** - * Purpose: Check that the regular code values are get without problems - * - * Cases considered: - * - Get code from new created dialog. - * - */ -START_TEST (test_get_code_regular) -{ - const gchar * code; - - /* Test 1: Get code from new created dialog. */ - /* Check that code is correctly get. */ - code = hildon_code_dialog_get_code (code_dialog); - fail_if (strcmp (code,"") != 0, - "hildon-code-dialog: init code isn't empty"); - -} -END_TEST - -/** - * Purpose: Check that the regular code values are get without problems - * - * Cases considered: - * - Get code from NULL object - * - Get code from object that isn't a code dialog. - * - */ -START_TEST (test_get_code_invalid) -{ - const gchar * code; - GtkWidget *aux_object = NULL; - - /* Test 1: Get code from NULL object. */ - code = hildon_code_dialog_get_code (NULL); - - /* Test 2: Get code from object that it isn't a code dialog. */ - aux_object = gtk_hbox_new (TRUE, 0); - code = hildon_code_dialog_get_code ((HildonCodeDialog *) aux_object); - - gtk_widget_destroy (aux_object); - -} -END_TEST - -/* ---------- Suite creation ---------- */ -Suite *create_hildon_code_dialog_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonCodeDialog"); - - /* Create test cases */ - TCase *tc1 = tcase_create("get_code"); - - /* Create test case for hildon_code_dialog_get_code and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_code_dialog, fx_teardown_default_code_dialog); - tcase_add_test(tc1, test_get_code_regular); - tcase_add_test(tc1, test_get_code_invalid); - suite_add_tcase (s, tc1); - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-color-button.c b/tests/check-hildon-color-button.c deleted file mode 100644 index 4edfeec..0000000 --- a/tests/check-hildon-color-button.c +++ /dev/null @@ -1,391 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkhbox.h> -#include <glib/gprintf.h> -#include "test_suites.h" -#include "check_utils.h" -#include <hildon/hildon-color-button.h> - -/* -------------------- Fixtures -------------------- */ -static HildonColorButton *color_button = NULL; -static GtkWidget *showed_window = NULL; - -static void -fx_setup_default_color_button() -{ - int argc = 0; - gtk_init(&argc, NULL); - - color_button = HILDON_COLOR_BUTTON(hildon_color_button_new()); - /* Check that the color button object has been created properly */ - - showed_window = create_test_window (); - - /* This packs the widget into the window (a gtk container). */ - gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (color_button)); - - /* Displays the widget and the window */ - show_all_test_window (showed_window); - - - fail_if(!HILDON_IS_COLOR_BUTTON(color_button), - "hildon-color-button: Creation failed."); - -} - -static void -fx_teardown_default_color_button() -{ - - /* Destroy the widget and the window */ - gtk_widget_destroy(GTK_WIDGET(showed_window)); - -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_color -----*/ -/** - * Purpose: Check that a regular color can be set safely - * Cases considered: - * - Set color defined by (255, 255, 255) and pixel = 255 - * - Set color defined by (10, 20, 30) and pixel = 10 - * - Set color defined by (20, 10, 30) and pixel = 10 - * - Set color defined by (30, 10, 20) and pixel = 20 - */ - -START_TEST (test_set_color_regular) -{ - GdkColor color; - GdkColor * b_color; - GdkColor * ret_color = g_new (GdkColor, 1); - guint red; - guint green; - guint blue; - guint pixel; - - b_color = gdk_color_copy(&color); - - /* Test 1: Set color defined by (255,255,255)*/ - red = 255; - green = 255; - blue = 255; - pixel = 255; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - b_color->pixel=pixel; - - hildon_color_button_set_color(color_button,b_color); - hildon_color_button_get_color(color_button, ret_color); - - fail_if ((red != ret_color->red) || (green != ret_color->green) || - (blue != ret_color->blue) || (pixel != ret_color->pixel), - "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d", - pixel, ret_color->red, ret_color->green, - ret_color->blue, ret_color->pixel); - - /* Test 2: Set color defined by (10,20,30)*/ - red = 10; - green = 20; - blue = 30; - pixel = 10; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - b_color->pixel=pixel; - - hildon_color_button_set_color(color_button,b_color); - hildon_color_button_get_color(color_button, ret_color); - - fail_if ((red != ret_color->red) || (green != ret_color->green) || - (blue != ret_color->blue) || (pixel != ret_color->pixel), - "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d", - pixel, ret_color->red, ret_color->green, - ret_color->blue, ret_color->pixel); - - /* Test 3: Set color defined by (20,10,30)*/ - red = 20; - green = 10; - blue = 30; - pixel = 10; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - b_color->pixel=pixel; - - hildon_color_button_set_color(color_button,b_color); - hildon_color_button_get_color(color_button, ret_color); - - fail_if ((red != ret_color->red) || (green != ret_color->green) || - (blue != ret_color->blue) || (pixel != ret_color->pixel), - "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d", - pixel, ret_color->red, ret_color->green, - ret_color->blue, ret_color->pixel); - - /* Test 4: Set color defined by (30,10,20)*/ - red = 30; - green = 10; - blue = 20; - pixel = 20; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - b_color->pixel=pixel; - - hildon_color_button_set_color(color_button,b_color); - hildon_color_button_get_color(color_button, ret_color); - - fail_if ((red != ret_color->red) || (green != ret_color->green) || - (blue != ret_color->blue) || (pixel != ret_color->pixel), - "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d", - pixel, ret_color->red, ret_color->green, - ret_color->blue, ret_color->pixel); - - if (b_color) - gdk_color_free(b_color); - - if (ret_color) - gdk_color_free(ret_color); -} -END_TEST - -/** - * Purpose: Check that a limits values on color components can be set safely. - * Cases considered: - * - Set color defined by (0, 0, 0) and pixel = 0 - * - Set color defined by (G_MAXUINT16, G_MAXUINT16, G_MAXUINT16) and pixel = G_MAXUINT32 - * - Set color defined by (G_MAXUINT16, 0, 0) and pixel = G_MAXUINT32 - * - Set color defined by (0, G_MAXUINT16, 0) and pixel = 0 - * - Set color defined by (0, 0, G_MAXUINT16) and pixel = G_MAXUINT32 - */ - -START_TEST (test_set_color_limits) -{ - GdkColor color; - GdkColor * b_color; - GdkColor * ret_color = g_new (GdkColor, 1); - guint red; - guint green; - guint blue; - guint pixel; - - b_color = gdk_color_copy(&color); - - /* Test 1: Set color defined by (0,0,0)*/ - red = 0; - green = 0; - blue = 0; - pixel = 0; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - b_color->pixel=pixel; - - hildon_color_button_set_color(color_button,b_color); - hildon_color_button_get_color(color_button, ret_color); - - fail_if ((red != ret_color->red) || (green != ret_color->green) || - (blue != ret_color->blue) || (pixel != ret_color->pixel), - "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d", - pixel, ret_color->red, ret_color->green, - ret_color->blue, ret_color->pixel); - - /* Test 2: Set color defined by (G_MAXUINT16,G_MAXUINT16,G_MAXUINT16)*/ - red = G_MAXUINT16; - green = G_MAXUINT16; - blue = G_MAXUINT16; - pixel = G_MAXUINT32; - - b_color->pixel=pixel; - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - - hildon_color_button_set_color(color_button,b_color); - hildon_color_button_get_color(color_button, ret_color); - - fail_if ((red != ret_color->red) || (green != ret_color->green) || - (blue != ret_color->blue) || (pixel != ret_color->pixel), - "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d", - pixel, ret_color->red, ret_color->green, - ret_color->blue, ret_color->pixel); - - /* Test 3: Set color defined by (G_MAXUINT16,0,0)*/ - red = G_MAXUINT16; - green = 0; - blue = 0; - pixel = G_MAXUINT32; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - b_color->pixel=pixel; - - hildon_color_button_set_color(color_button,b_color); - hildon_color_button_get_color(color_button, ret_color); - - fail_if ((red != ret_color->red) || (green != ret_color->green) || - (blue != ret_color->blue) || (pixel != ret_color->pixel), - "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d", - pixel, ret_color->red, ret_color->green, - ret_color->blue, ret_color->pixel); - - /* Test 4: Set color defined by (0,G_MAXUINT16,0)*/ - red = 0; - green = G_MAXUINT16; - blue = 0; - pixel = 0; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - b_color->pixel=pixel; - - hildon_color_button_set_color(color_button,b_color); - hildon_color_button_get_color(color_button, ret_color); - - fail_if ((red != ret_color->red) || (green != ret_color->green) || - (blue != ret_color->blue) || (pixel != ret_color->pixel), - "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d", - pixel, ret_color->red, ret_color->green, - ret_color->blue, ret_color->pixel); - - /* Test 5: Set color defined by (0,0,G_MAXUINT16)*/ - red = 0; - green = 0; - blue = G_MAXUINT16; - pixel = G_MAXUINT32; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - b_color->pixel=pixel; - - hildon_color_button_set_color(color_button,b_color); - hildon_color_button_get_color(color_button, ret_color); - - fail_if ((red != ret_color->red) || (green != ret_color->green) || - (blue != ret_color->blue) || (pixel != ret_color->pixel), - "hildon-color-button: The returned color for the pixel %d (returned %d) in RGB is %d/%d/%d and should be %d/%d/%d", - pixel, ret_color->red, ret_color->green, - ret_color->blue, ret_color->pixel); - - if (b_color) - gdk_color_free(b_color); - - if (ret_color) - gdk_color_free(ret_color); -} -END_TEST - -/** - * Purpose: Check that a limits values on color components can be set safely. - * Cases considered: - * - Set color defined by (0, 0, 0) on NULL object. - * - Get color from NULL object. - * - Set color defined by (0, 0, 0) on GtkHBox object. - * - Get a color from GtkHBox object. - */ - -START_TEST (test_set_color_invalid) -{ - GdkColor color; - GdkColor * b_color; - GdkColor * ret_color = g_new (GdkColor, 1); - GtkWidget *aux_object = NULL; - guint red; - guint green; - guint blue; - - b_color = gdk_color_copy(&color); - - red = 0; - green = 0; - blue = 0; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - b_color->pixel=0; - - /* Test 1: Set color defined by (0,0,0) on NULL object*/ - hildon_color_button_set_color(NULL,b_color); - - /* Test 2: Get color from NULL object*/ - hildon_color_button_get_color(NULL, ret_color); - - /* Test 3: Set color defined by (0, 0, 0) on GtkHBox object. */ - aux_object = gtk_hbox_new (TRUE, 0); - hildon_color_button_set_color((HildonColorButton *) (aux_object), b_color); - gdk_color_free(b_color); - - /* Test 4: Get color from GtkHBox object. */ - ret_color->red = 99; - ret_color->green = 99; - ret_color->blue = 99; - hildon_color_button_get_color((HildonColorButton *) (aux_object), ret_color); - - if (ret_color->red != 99 || - ret_color->green != 99 || - ret_color->blue != 99) - { - gtk_widget_destroy(aux_object); - fail ("hildon-color-button: get_color must not modify the color when launched on invalid widget"); - } - - gtk_widget_destroy(aux_object); - g_free (ret_color); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_color_button_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonColorButton"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_color"); - - /* Create test case for hildon_color_button_set_color and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_color_button, fx_teardown_default_color_button); - tcase_add_test(tc1, test_set_color_regular); - tcase_add_test(tc1, test_set_color_limits); - tcase_add_test(tc1, test_set_color_invalid); - suite_add_tcase(s, tc1); - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-color-chooser.c b/tests/check-hildon-color-chooser.c deleted file mode 100644 index ed51741..0000000 --- a/tests/check-hildon-color-chooser.c +++ /dev/null @@ -1,276 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <glib/gprintf.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-color-chooser.h> -#include <hildon/hildon-window.h> - -#define MAX_COLOR 65535 - -/* -------------------- Fixtures -------------------- */ -static HildonColorChooser *color_chooser = NULL; -static GtkWindow * cs_window; - -static void -fx_setup_default_color_chooser () -{ - int argc = 0; - gtk_init(&argc, NULL); - - cs_window = GTK_WINDOW(create_test_window()); - - /* Check window object has been created properly */ - fail_if(!HILDON_IS_WINDOW(cs_window), - "hildon-color-chooser: Window creation failed."); - - color_chooser = HILDON_COLOR_CHOOSER(hildon_color_chooser_new()); - /* Check that the color chooser object has been created properly */ - fail_if(!HILDON_IS_COLOR_CHOOSER(color_chooser), - "hildon-color-chooser: Creation failed."); - - gtk_container_add (GTK_CONTAINER(cs_window), GTK_WIDGET (color_chooser)); - - show_all_test_window(GTK_WIDGET(cs_window)); - show_all_test_window(GTK_WIDGET(color_chooser)); - -} - -static void -fx_teardown_default_color_chooser () -{ - gtk_widget_destroy (GTK_WIDGET (color_chooser)); - gtk_widget_destroy (GTK_WIDGET (cs_window)); - -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_color -----*/ - -/** - * Purpose: Check that regular base colors are set and get properly - * Cases considered: - * - Set the color #33CC33. - */ -START_TEST (test_set_color_regular) -{ - GdkColor color; - GdkColor * b_color; - GdkColor * ret_color = g_new (GdkColor, 1); - - /* Test 1: Set the color #33CC33*/ - gdk_color_parse( "#33CC33", &color); - b_color = gdk_color_copy(&color); - - hildon_color_chooser_set_color(color_chooser,b_color); - hildon_color_chooser_get_color(color_chooser, ret_color); - - fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) || - (b_color->blue != ret_color->blue), - "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i", - ret_color->red, ret_color->green, ret_color->blue, - b_color->red, b_color->green, b_color->blue); - - if (b_color) - gdk_color_free(b_color); - - if (ret_color) - gdk_color_free(ret_color); -} -END_TEST - -/** - * Purpose: Check that limits base colors are set and get properly - * Cases considered: - * - Set and get base color defined by #000000. - * - Set and get base color defined by #FFFFFF. - * - Set and get base color defined by #FF0000. - * - Set and get base color defined by #0000FF. - */ -START_TEST (test_set_color_limits) -{ - GdkColor color; - GdkColor * b_color; - GdkColor * ret_color = g_new (GdkColor, 1); - - /* Check that the color chooser object has been created properly */ - fail_if(!HILDON_IS_COLOR_CHOOSER(color_chooser), - "hildon-color-chooser: Creation failed."); - - /* Test 1: Set the color #000000 */ - gdk_color_parse( "#000000", &color); - b_color = gdk_color_copy(&color); - - hildon_color_chooser_set_color(color_chooser,b_color); - hildon_color_chooser_get_color(color_chooser, ret_color); - - fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) || - (b_color->blue != ret_color->blue), - "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i", - ret_color->red, ret_color->green, ret_color->blue, - b_color->red, b_color->green, b_color->blue); - - gdk_color_free(b_color); - - - /* Test 2: Set the color #FFFFFF */ - gdk_color_parse( "#000000", &color); - b_color = gdk_color_copy(&color); - - hildon_color_chooser_set_color(color_chooser,b_color); - hildon_color_chooser_get_color(color_chooser, ret_color); - - fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) || - (b_color->blue != ret_color->blue), - "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i", - ret_color->red, ret_color->green, ret_color->blue, - b_color->red, b_color->green, b_color->blue); - - gdk_color_free(b_color); - - - /* Test 3: Set the color #FF0000 */ - gdk_color_parse( "#FF0000", &color); - b_color = gdk_color_copy(&color); - - hildon_color_chooser_set_color(color_chooser,b_color); - hildon_color_chooser_get_color(color_chooser, ret_color); - - fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) || - (b_color->blue != ret_color->blue), - "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i", - ret_color->red, ret_color->green, ret_color->blue, - b_color->red, b_color->green, b_color->blue); - - gdk_color_free(b_color); - - /* Test 4: Set the color to #0000FF*/ - gdk_color_parse( "#0000FF", &color); - b_color = gdk_color_copy(&color); - - hildon_color_chooser_set_color(color_chooser,b_color); - hildon_color_chooser_get_color(color_chooser, ret_color); - - fail_if ((b_color->red != ret_color->red) || (b_color->green != ret_color->green) || - (b_color->blue != ret_color->blue), - "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i", - ret_color->red, ret_color->green, ret_color->blue, - b_color->red, b_color->green, b_color->blue); - - if (b_color) - gdk_color_free(b_color); - - if (ret_color) - gdk_color_free(ret_color); -} -END_TEST -/** - * Purpose: Check that invalid base colors are set and get properly - * Cases considered: - * - Set the color (65536,65536,65536). - * - Set and get base color defined by NULL color. - * - Set base color on NULL object. - * - Get base color from NULL object. - */ -START_TEST (test_set_color_invalid) -{ - GdkColor color; - GdkColor * b_color; - GdkColor * ret_color = g_new (GdkColor, 1); - guint red; - guint green; - guint blue; - - /* Check that the color chooser object has been created properly */ - fail_if(!HILDON_IS_COLOR_CHOOSER(color_chooser), - "hildon-color-chooser: Creation failed."); - - /* Initialize color to check that invalid values doesn't set colors*/ - gdk_color_parse( "#000000", &color); - b_color = gdk_color_copy(&color); - - hildon_color_chooser_set_color(color_chooser,b_color); - gdk_color_free(b_color); - - - /* Test 1: Set the color (65536,65536,65536)*/ - gdk_color_parse( "#000000", &color); - b_color = gdk_color_copy(&color); - red = MAX_COLOR+1; - green = MAX_COLOR+1; - blue = MAX_COLOR+1; - - b_color->red=red; - b_color->green=green; - b_color->blue=blue; - - hildon_color_chooser_set_color(color_chooser,b_color); - hildon_color_chooser_get_color(color_chooser, ret_color); - - fail_if ((0 != ret_color->red) || (0 != ret_color->green) || (0 != ret_color->blue), - "hildon-color-chooser: The returned RGB color is %i/%i/%i and should be %i/%i/%i", - ret_color->red, ret_color->green, ret_color->blue, - 0, 0, 0); - - /* Test 2: Set the color NULL on color chooser*/ - hildon_color_chooser_set_color(color_chooser,NULL); - - /* Test 3: Set the color on NULL object*/ - hildon_color_chooser_set_color(NULL,b_color); - - /* Test 4: Get color from NULL object*/ - hildon_color_chooser_get_color(NULL, ret_color); - - if (b_color) - gdk_color_free(b_color); - - if (ret_color) - gdk_color_free(ret_color); -} -END_TEST - - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_color_chooser_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonColorChooser"); - - /* Create test case for hildon_color_chooser_set_color and add it to the suite */ - TCase *tc1 = tcase_create("set_color"); - tcase_add_checked_fixture(tc1, fx_setup_default_color_chooser, fx_teardown_default_color_chooser); - tcase_add_test(tc1, test_set_color_regular); - tcase_add_test(tc1, test_set_color_limits); - tcase_add_test(tc1, test_set_color_invalid); - suite_add_tcase (s, tc1); - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-controlbar.c b/tests/check-hildon-controlbar.c deleted file mode 100644 index efab1be..0000000 --- a/tests/check-hildon-controlbar.c +++ /dev/null @@ -1,418 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkcontainer.h> -#include "test_suites.h" -#include "check_utils.h" -#include <hildon/hildon-controlbar.h> - -/* -------------------- Fixtures -------------------- */ -static HildonControlbar *controlbar = NULL; -static GtkWidget *showed_window = NULL; - -static void -fx_setup_default_controlbar () -{ - int argc = 0; - gtk_init(&argc, NULL); - - controlbar = HILDON_CONTROLBAR(hildon_controlbar_new()); - /* Check controlbar object has been created properly */ - fail_if(!HILDON_IS_CONTROLBAR(controlbar), - "hildon-controlbar: Creation failed."); - - showed_window = create_test_window (); - - /* This packs the widget into the window (a gtk container). */ - gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (controlbar)); - - /* Displays the widget and the window */ - show_all_test_window (showed_window); - -} - -static void -fx_teardown_default_controlbar () -{ - - /* Destroy the widget and the window */ - gtk_widget_destroy (GTK_WIDGET(showed_window)); - -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_range -----*/ -/** - * Purpose: Check that regular range values are set and get properly - * Cases considered: - * - Set a range of [20,1000]. - * - Set a range of [20,20]. - */ -START_TEST (test_set_range_regular) -{ - gint init_min; - gint init_max; - gint min; - gint max; - - /* Test 1: Set a range of [20,1000] */ - init_min = 20; - init_max = 1000; - hildon_controlbar_set_range(controlbar,init_min,init_max); - - min = hildon_controlbar_get_min(controlbar); - - fail_if (min != init_min, - "hildon-controlbar: The returned min is %d and should be %d", - min, init_min); - - max = hildon_controlbar_get_max(controlbar); - - fail_if (max != init_max, - "hildon-controlbar: The returned max is %d and should be %d", - max, init_max); - - /* Test 2: Set a range of [20, 20] */ - init_min = 20; - init_max = 20; - hildon_controlbar_set_range(controlbar,init_min,init_max); - - min = hildon_controlbar_get_min(controlbar); - - fail_if (min != init_min, - "hildon-controlbar: The returned min is %d and should be %d", - min, init_min); - - max = hildon_controlbar_get_max(controlbar); - - fail_if (max != init_max, - "hildon-controlbar: The returned max is %d and should be %d", - max, init_max); - -} -END_TEST - -/** - * Purpose: Check that limits range values are set and get properly - * Cases considered: - * - Set a range of [0,G_MAXINT-1]. - */ -START_TEST (test_set_range_limits) -{ - gint init_min; - gint init_max; - gint min; - gint max; - - /* Test 1: Set a range of [0,G_MAXINT-1] */ - init_min = 0; - init_max = G_MAXINT-1; - hildon_controlbar_set_range(controlbar,init_min,init_max); - - min=hildon_controlbar_get_min(controlbar); - - fail_if (min != init_min, - "hildon-controlbar: The returned min is %d and should be %d", - min, init_min); - - max=hildon_controlbar_get_max(controlbar); - - fail_if (max != init_max, - "hildon-controlbar: The returned max is %d and should be %d", - max, init_max); -} -END_TEST - -/** - * Purpose: Check that invalid range values are set and get properly - * Cases considered: - * - Set a range of [10,100] on NULL object. - * - Set a range of [-1,G_MAXINT]. - * - Set a range of [G_MININT,-1]. - * - Set a range of [G_MAXINT,-1]. - * - Set a range of [1,G_MININT]. - */ -START_TEST (test_set_range_invalid) -{ - gint init_min; - gint init_max; - gint min; - gint max; - - init_min = 10; - init_max = 100; - /* Test 1: Set range on a NULL object */ - hildon_controlbar_set_range(NULL,init_min,init_max); - - init_min = -1; - init_max = G_MAXINT; - /* Test 2: Set a range of [-1,G_MAXINT] */ - hildon_controlbar_set_range(controlbar,init_min,init_max); - - min=hildon_controlbar_get_min(controlbar); - - fail_if (min != init_min, - "hildon-controlbar: The returned min is %d and should be %d", - min, init_min); - - max=hildon_controlbar_get_max(controlbar); - - fail_if (max != init_max, - "hildon-controlbar: The returned max is %d and should be %d", - max, init_max); - - /* Test 3: Set a range of [G_MININT,-1] */ - init_min = G_MININT; - init_max = -1; - hildon_controlbar_set_range(controlbar,init_min,init_max); - - min=hildon_controlbar_get_min(controlbar); - - fail_if (min != init_min, - "hildon-controlbar: The returned min is %d and should be %d", - min, init_min); - max=hildon_controlbar_get_max(controlbar); - - fail_if (max != init_max, - "hildon-controlbar: The returned max is %d and should be %d", - max, init_max); - - /* Test 4: Set a range of [G_MAXINT,-1] */ - init_min = G_MAXINT; - init_max = -1; - hildon_controlbar_set_range(controlbar,init_min,init_max); - - max=hildon_controlbar_get_max(controlbar); - - fail_if (max != init_max, - "hildon-controlbar: The returned max is %d and should be %d", - max, init_max); - - min=hildon_controlbar_get_min(controlbar); - - fail_if (min != init_max, - "hildon-controlbar: The returned min is %d and should be %d", - min, init_max); - - /* NOTE: The test below has been deliverately commented out, since - it fails miserably. The range check in hildon_control_bar_set_range() - is _broken_ and fixing it causes other tests to fail. It is safe to assume - that by now, fixing this is going to cause more headaches than anything else, - and being this a deprecated widget, there is no point on wasting time on it. - */ - - /* Test 5: Set a range of [1,G_MININT] */ -#if 0 - init_min = 1; - init_max = G_MININT; - hildon_controlbar_set_range(controlbar,init_min,init_max); - - max=hildon_controlbar_get_max(controlbar); - - fail_if (max != init_min, - "hildon-controlbar: The returned max is %d and should be %d", - max, init_min); - - min=hildon_controlbar_get_min(controlbar); - - fail_if (min != init_min, - "hildon-controlbar: The returned min is %d and should be %d", - min, init_min); -#endif -} -END_TEST - -/* ----- Test case for set_value -----*/ -/** - * Purpose: Check that regular values are set and get properly - * Cases considered: - * - Set a value of 500 in the range [0,1000]. - */ -START_TEST (test_set_value_regular) -{ - gint init_value; - gint value; - - init_value=500; - /* Must set a range different than [0,0], if not set you can not set a value*/ - hildon_controlbar_set_range(controlbar,0,1000); - - /* Test 1: Set a value of 500 in the range [0,1000].*/ - hildon_controlbar_set_value(controlbar,init_value); - value=hildon_controlbar_get_value(controlbar); - fail_if (value != init_value, - "hildon-controlbar: The returned value is %d and should be %d", - value, init_value); - -} -END_TEST - -/** - * Purpose: Check that limit values are set and get properly - * Cases considered: - * - Set a value of 0 in the range [0,1000]. - * - Set a value of 1000 in the range [0,1000]. - */ -START_TEST (test_set_value_limits) -{ - gint init_value; - gint value; - - /* Must set a range diferent than [0,0], if not set you can not set a value*/ - hildon_controlbar_set_range(controlbar,0,1000); - - /* Test 1: Set a value of 0 in the range [0,1000] */ - init_value=0; - - hildon_controlbar_set_value(controlbar,init_value); - value=hildon_controlbar_get_value(controlbar); - fail_if (value != init_value, - "hildon-controlbar: The returned value is %d and should be %d", - value, init_value); - - /* Test 2: Set a value of 1000 in the range [0,1000] */ - init_value=1000; - - hildon_controlbar_set_value(controlbar,init_value); - value=hildon_controlbar_get_value(controlbar); - fail_if (value != init_value, - "hildon-controlbar: The returned value is %d and should be %d", - value, init_value); -} -END_TEST - - -/** - * Purpose: Check that invalid values are set and get properly - * Cases considered: - * - Set a value of 1 in a NULL controlbar. - * - Set a value of -1 in the range [2,1000]. - * - Set a value of 1 in the range [2,1000]. - * - Set a value of G_MININT in the range [2,1000]. - * - Set a value of 1001 in the range [2,1000]. - * - Set a value of G_MAXINT in the range [2,1000]. - * - Set a value of G_MAXINT in the range [2,G_MAXINT]. - */ -START_TEST (test_set_value_invalid) -{ - gint init_value; - gint initial_value=4; - gint value; - gint current_value; - gint min_value; - gint max_value; - - min_value = 2; - max_value = 1000; - /* Must set a range diferent than [0,0], if not set you can not set a value*/ - hildon_controlbar_set_range(controlbar,min_value,max_value); - hildon_controlbar_set_value(controlbar,initial_value); - - /* Test 1: Set a value of 1 in a NULL controlbar. */ - init_value=10; - hildon_controlbar_set_value(NULL,init_value); - - - /* Test 2: Set a value of -1 in the range [2,1000] */ - init_value=-1; - hildon_controlbar_set_value(controlbar,init_value); - value=hildon_controlbar_get_value(controlbar); - fail_if (value != initial_value, - "hildon-controlbar: The returned value is %d and should be %d", - value, initial_value); - - /* Test 3: Set a value of 1 in the range [2,1000] */ - init_value=1; - hildon_controlbar_set_value(controlbar,min_value); - - hildon_controlbar_set_value(controlbar,init_value); - value=hildon_controlbar_get_value(controlbar); - fail_if (value != min_value, - "hildon-controlbar: The returned value is %d and should be %d", - value, min_value); - - - /* Test 4: Set a value of G_MININT in the range [2,1000] */ - init_value=G_MININT; - hildon_controlbar_set_value(controlbar,min_value+2); - current_value = hildon_controlbar_get_value(controlbar); - - hildon_controlbar_set_value(controlbar,init_value); - value=hildon_controlbar_get_value(controlbar); - fail_if (value != current_value, - "hildon-controlbar: The returned value is %d and should be %d", - value, current_value); - - /* Test 5: Set a value of 1001 in the range [2,1000] */ - init_value=1001; - - hildon_controlbar_set_value(controlbar,init_value); - value=hildon_controlbar_get_value(controlbar); - fail_if (value != max_value, - "hildon-controlbar: The returned value is %d and should be %d", - value, max_value); - - - /* Test 6: Set a value of G_MAXINT in the range [2,1000] */ - init_value=G_MAXINT; - - hildon_controlbar_set_value(controlbar,init_value); - value=hildon_controlbar_get_value(controlbar); - fail_if (value != max_value, - "hildon-controlbar: The returned value is %d and should be %d", - value, max_value); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_controlbar_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonControlbar"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_range"); - TCase *tc2 = tcase_create("set_value"); - - /* Create test case for hildon_controlbar_set_range and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_controlbar, fx_teardown_default_controlbar); - tcase_add_test(tc1, test_set_range_regular); - tcase_add_test(tc1, test_set_range_limits); - tcase_add_test(tc1, test_set_range_invalid); - suite_add_tcase (s, tc1); - - /* Create test case for hildon_controlbar_set_value and add it to the suite */ - tcase_add_checked_fixture(tc2, fx_setup_default_controlbar, fx_teardown_default_controlbar); - tcase_add_test(tc2, test_set_value_regular); - tcase_add_test(tc2, test_set_value_limits); - tcase_add_test(tc2, test_set_value_invalid); - suite_add_tcase (s, tc2); - - return s; -} diff --git a/tests/check-hildon-date-editor.c b/tests/check-hildon-date-editor.c deleted file mode 100644 index ea953d5..0000000 --- a/tests/check-hildon-date-editor.c +++ /dev/null @@ -1,1040 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkhbox.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-date-editor.h> - -/* Taken from the values of the properties of HildonDateEditor */ -#define MAX_YEAR 2037 -#define MAX_MONTH 12 -#define MAX_DAY 31 -#define MIN_YEAR 1970 -#define MIN_MONTH 1 -#define MIN_DAY 1 - -/* -------------------- Fixtures -------------------- */ - -static HildonDateEditor *date_editor = NULL; -static GtkWidget *showed_window = NULL; - -static void -fx_setup_default_date_editor () -{ - int argc = 0; - - gtk_init(&argc, NULL); - - showed_window = create_test_window (); - - date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new()); - /* Check that the date editor object has been created properly */ - fail_if(!HILDON_IS_DATE_EDITOR(date_editor), - "hildon-date-editor: Creation failed."); - - /* This packs the widget into the window (a gtk container). */ - gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (date_editor)); - - /* Displays the widget and the window */ - show_all_test_window (showed_window); -} - -static void -fx_teardown_default_date_editor () -{ - - /* Destroy the widget and the window */ - gtk_widget_destroy (GTK_WIDGET (showed_window)); - -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_date -----*/ - -/** - * Purpose: test setting regular values for hildon_date_editor_set_date - * Cases considered: - * - Set and get the date 30/03/1981 - */ -START_TEST (test_set_date_regular) -{ - guint year, month, day; - guint ret_year, ret_month, ret_day; - - year = 1981; - month = 3; - day = 30; - - /* Test 1: Try date 30/3/1981 */ - hildon_date_editor_set_date (date_editor, year, month, day); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day), - "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u", - ret_year, ret_month, ret_day, year, month, day); -} -END_TEST - -static void -test_set_date_limits_check (guint year, guint month, guint day) -{ - guint ret_year, ret_month, ret_day; - - hildon_date_editor_set_date (date_editor, year, month, day); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day), - "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u", - ret_year, ret_month, ret_day, year, month, day); -} - -/** - * Purpose: test limit date values for hildon_date_editor_set_date - * Cases considered: - * - test a year value equal to the year limits (1970, 2037) - * - test a month value equal to the month limits (1, 12) - * - test a day value equal to the day limits for March (1, 31) - * - test a day value equal to the day limits June (1, 30) - * - test a day value equal to the day limit for a common February (28-2-1981) - * - test a day value equal to the day limit for a February of a leap year (29-2-1980) - */ -START_TEST (test_set_date_limits) -{ - guint year, month, day; - - year = MIN_YEAR; - month = 3; - day = 30; - - /* Test 1: Test year limits */ - test_set_date_limits_check (year, month, day); - - year = MAX_YEAR; - test_set_date_limits_check (year, month, day); - - /* Test 2: Test month limits */ - year = 1981; - month = MIN_MONTH; - day = 30; - test_set_date_limits_check (year, month, day); - - month = MAX_MONTH; - test_set_date_limits_check (year, month, day); - - /* Test 3: Test day limits */ - year = 1981; - month = 3; - day = 31; - test_set_date_limits_check (year, month, day); - - /* Test 4: Test day limits */ - year = 1981; - month = 6; - day = 30; - test_set_date_limits_check (year, month, day); - - /* Test 5: Test february limits */ - year = 1981; - month = 2; - day = 28; - test_set_date_limits_check (year, month, day); - - /* Test 6: Test february limits for a leap year */ - year = 1980; - month = 2; - day = 29; - test_set_date_limits_check (year, month, day); -} -END_TEST - -/** - * Purpose: test invalid parameter values for hildon_date_editor_set_date - * Cases considered: - * - test NULL widget - * - test passing GtkHBox instead a HildonDateEditor - * - test leap year - * - test negative values - * - test invalid month days - * - test a year value lower and higher than the year limits (1970, 2037) - * - test a month value lower and higher than the year limits (1, 12) - * - test a day value lower and higher than the year limits (1, 31) - */ -START_TEST (test_set_date_invalid) -{ - guint year, month, day; - guint ret_year, ret_month, ret_day; - GtkWidget *aux_object = NULL; - - year = 1981; - month = 3; - day = 30; - - /* Set init date */ - hildon_date_editor_set_date (date_editor, year, month, day); - - /* Test 1: Test NULL */ - hildon_date_editor_set_date (NULL, year, month, day); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day), - "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u", - ret_year, ret_month, ret_day, year, month, day); - - /* Test 2: Test another object */ - aux_object = gtk_hbox_new (TRUE, 0); - hildon_date_editor_set_date ((HildonDateEditor *) (aux_object), year, month, day); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day), - "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u", - ret_year, ret_month, ret_day, year, month, day); - gtk_widget_destroy (GTK_WIDGET(aux_object)); - - /* Test 3: Test leap year */ - hildon_date_editor_set_date (date_editor, year, 2, 29); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day), - "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u", - ret_year, ret_month, ret_day, year, month, day); - - /* Restore the original value */ - hildon_date_editor_set_date (date_editor, year, month, day); - - /* Test 4: Test negative values */ - hildon_date_editor_set_date (date_editor, -year, -month, -day); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day), - "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u", - ret_year, ret_month, ret_day, year, month, day); - - /* Test 5: Test invalid month days */ - hildon_date_editor_set_date (date_editor, year, 11, 31); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day), - "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u", - ret_year, ret_month, ret_day, year, month, day); - - /* Test 6: Test year invalid values, the year value could be set - under/over the value of the property because the date is not - validated if the value was not set through the user interface */ - hildon_date_editor_set_date (date_editor, MIN_YEAR - 1, month, day); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if (ret_year != (MIN_YEAR - 1), - "hildon-date-editor: The returned year is %u and should be %u", - ret_year, MIN_YEAR - 1); - - hildon_date_editor_set_date (date_editor, MAX_YEAR + 1, month, day); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if (ret_year != MAX_YEAR + 1, - "hildon-date-editor: The returned year is %u and should be %u", - ret_year, MAX_YEAR + 1); - - /* Test 7: Test month invalid values, we do not have the same - problem with the years because both month 0 and 13 are not valid - for g_date */ - hildon_date_editor_set_date (date_editor, year, MIN_MONTH - 1, day); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if (ret_month != month, - "hildon-date-editor: The returned month is %u and should be %u", - ret_month, month); - - hildon_date_editor_set_date (date_editor, year, MAX_MONTH + 1, day); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if (ret_month != month, - "hildon-date-editor: The returned month is %u and should be %u", - ret_month, month); - - /* Test 8: Test day invalid values */ - hildon_date_editor_set_date (date_editor, year, month, MIN_DAY - 1); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if (ret_day != day, - "hildon-date-editor: The returned day is %u and should be %u", - ret_day, day); - - hildon_date_editor_set_date (date_editor, year, month, MAX_DAY + 1); - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - fail_if (ret_day != day, - "hildon-date-editor: The returned day is %u and should be %u", - ret_day, day); -} -END_TEST - -/* ----- Test case for get_date -----*/ - -/* We do not include tests for limit values because we think they're - tested enought with the set_data tests */ - -/** - * Purpose: test getting regular values for hildon_date_editor_get_date - * Cases considered: - * - Set and get date 30/03/1981 - */ -START_TEST (test_get_date_regular) -{ - guint year, month, day; - guint ret_year, ret_month, ret_day; - GValue value = { 0, }; - - year = 1981; - month = 3; - day = 30; - - /* Test 1: Test regular values */ - hildon_date_editor_set_date (NULL, year, month, day); - - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day); - - g_value_init (&value, G_TYPE_UINT); - g_object_get_property (G_OBJECT (date_editor), "year", &value); - fail_if (g_value_get_uint (&value) != ret_year, - "hildon-date-editor: get_date failed. The returned year is %u and should be %u", - g_value_get_uint (&value), - ret_year); - - g_value_unset (&value); - g_value_init (&value, G_TYPE_UINT); - g_object_get_property (G_OBJECT (date_editor), "month", &value); - fail_if (g_value_get_uint (&value) != ret_month, - "hildon-date-editor: get_date failed. The returned month is %u and should be %u", - g_value_get_uint (&value), - ret_month); - - g_value_unset (&value); - g_value_init (&value, G_TYPE_UINT); - g_object_get_property (G_OBJECT (date_editor), "day", &value); - fail_if (g_value_get_uint (&value) != ret_day, - "hildon-date-editor: get_date failed. The returned day is %u and should be %u", - g_value_get_uint (&value), - ret_day); -} -END_TEST - -/** - * Purpose: test getting regular values passing invalid arguments for - * hildon_date_editor_get_date - * Cases considered: - * - HildonDateEditor NULL - * - year is NULL - * - month is NULL - * - day is NULL - */ -START_TEST (test_get_date_invalid) -{ - guint year, month, day; - guint ret_year, ret_month, ret_day; - - year = 1981; - month = 3; - day = 30; - - hildon_date_editor_set_date (date_editor, year, month, day); - - /* Check that does not fail */ - hildon_date_editor_get_date (NULL, &ret_year, &ret_month, &ret_day); - - /* Check NULL arguments */ - hildon_date_editor_get_date (date_editor, NULL, &ret_month, &ret_day); - fail_if (hildon_date_editor_get_year (date_editor) != year, - "hildon-date-editor: get_date failed. The returned year is %u and should be %u", - ret_year, year); - - hildon_date_editor_get_date (date_editor, &ret_year, NULL, &ret_day); - fail_if (hildon_date_editor_get_month (date_editor) != month, - "hildon-date-editor: get_date failed. The returned month is %u and should be %u", - ret_month, month); - - hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, NULL); - fail_if (hildon_date_editor_get_day (date_editor) != day, - "hildon-date-editor: get_date failed. The returned day is %u and should be %u", - ret_day, day); -} -END_TEST - -/* ----- Test case for get_year -----*/ - -/** - * Purpose: test getting regular values of the year for hildon_date_editor_get_year - * Cases considered: - * - get a year set with set_date 30/03/1981 - * - get a year set with set_year 1980 - * - get a year set with set_property 2004 - */ -START_TEST (test_get_year_regular) -{ - guint year, month, day; - GValue value = {0, }; - - year = 1981; - month = 3; - day = 30; - - /* Test 1: Set year with set_date */ - hildon_date_editor_set_date (date_editor, year, month, day); - - fail_if (hildon_date_editor_get_year (date_editor) != year, - "hildon-date-editor: get_year failed. The returned year is %u and should be %u", - hildon_date_editor_get_year (date_editor), year); - - /* Test 2: set year with set_year */ - year = 1980; - hildon_date_editor_set_year (date_editor, year); - - fail_if (hildon_date_editor_get_year (date_editor) != year, - "hildon-date-editor: get_year failed. The returned year is %u and should be %u", - hildon_date_editor_get_year (date_editor), year); - - /* Test 3: set year with set_property */ - year = 2004; - g_value_init (&value, G_TYPE_UINT); - g_value_set_uint (&value, year); - g_object_set_property (G_OBJECT (date_editor), "year", &value); - - fail_if (hildon_date_editor_get_year (date_editor) != year, - "hildon-date-editor: get_year failed. The returned year is %u and should be %u", - hildon_date_editor_get_year (date_editor), year); -} -END_TEST - -/** - * Purpose: test getting year when a value over the limits was set for - * hildon_date_editor_get_year - * Cases considered: - * - test year 2037 - * - test year 1970 - */ -START_TEST (test_get_year_limits) -{ - guint year; - - year = 1981; - - /* Set init year */ - hildon_date_editor_set_year (date_editor, year); - - /* Test 1: upper limit */ - hildon_date_editor_set_year (date_editor, MAX_YEAR); - - fail_if (hildon_date_editor_get_year (date_editor) != MAX_YEAR, - "hildon-date-editor: The returned year is %u and should be %u", - hildon_date_editor_get_year (date_editor), MAX_YEAR); - - /* Test 2: lower limit */ - hildon_date_editor_set_year (date_editor, MIN_YEAR); - - fail_if (hildon_date_editor_get_year (date_editor) != MIN_YEAR, - "hildon-date-editor: The returned year is %u and should be %u", - hildon_date_editor_get_year (date_editor), MIN_YEAR); -} -END_TEST - -/** - * Purpose: test getting a year for invalid attributes for - * hildon_date_editor_get_year - * Cases considered: - * - HildonDateEditor is NULL - * - Pass a GtkHBox instead a HildonDateEditor - * - test year 2038 - * - test year 1969 - */ -START_TEST (test_get_year_invalid) -{ - guint ret_year; - GtkWidget *aux_object = NULL; - - /* Test 1: Test NULL */ - ret_year = hildon_date_editor_get_year (NULL); - fail_if (ret_year != 0, - "hildon-date-editor: get_year failed. The returned year is %u and should be %u", - ret_year, 0); - - /* Test 2: another object */ - aux_object = gtk_hbox_new (TRUE, 0); - ret_year = hildon_date_editor_get_year ((HildonDateEditor *) (aux_object)); - fail_if (ret_year != 0, - "hildon-date-editor: get_year failed. The returned year is %u and should be %u", - ret_year, 0); - gtk_widget_destroy (GTK_WIDGET(aux_object)); - - /* Test 3: upper limit, the test is OK but it shouldn't. The reason - is that the value of the date is not validated by Hildon since it - was not set using the UI */ - hildon_date_editor_set_year (date_editor, MAX_YEAR + 1); - - fail_if (hildon_date_editor_get_year (date_editor) != MAX_YEAR + 1, - "hildon-date-editor: The returned year is %u and should be %u", - hildon_date_editor_get_year (date_editor), MAX_YEAR + 1); - - /* Test 4: lower limit, see the above comment */ - hildon_date_editor_set_year (date_editor, MIN_YEAR - 1); - - fail_if (hildon_date_editor_get_year (date_editor) != MIN_YEAR - 1, - "hildon-date-editor: The returned year is %u and should be %u", - hildon_date_editor_get_year (date_editor), MIN_YEAR - 1); -} -END_TEST - -/* ----- Test case for set_year -----*/ - -/** - * Purpose: test setting a regular value for a year for - * hildon_date_editor_set_year - * Cases considered: - * - Set year 1981 - */ -START_TEST (test_set_year_regular) -{ - guint year; - guint ret_year; - - year = 1981; - - /* Test 1: Try year 1981 */ - hildon_date_editor_set_year (date_editor, year); - ret_year = hildon_date_editor_get_year (date_editor); - - fail_if (ret_year != year, - "hildon-date-editor: set_year failed. The returned year is %u and should be %u", - ret_year, year); -} -END_TEST - -/** - * Purpose: test setting values of the year over the limits for - * hildon_date_editor_set_year - * Cases considered: - * - Set year 2037 - * - Set year 1970 - */ -START_TEST (test_set_year_limits) -{ - guint year; - GValue value = { 0, }; - - year = 1981; - - /* Set init date */ - hildon_date_editor_set_year (date_editor, year); - - /* Test 1: Test upper limit */ - g_value_init (&value, G_TYPE_UINT); - hildon_date_editor_set_year (date_editor, MAX_YEAR); - g_object_get_property (G_OBJECT (date_editor), "year", &value); - fail_if (g_value_get_uint (&value) != MAX_YEAR, - "hildon-date-editor: The returned year is %u and should be %u", - g_value_get_uint (&value), year); - - /* Test 2: Test lower limit */ - g_value_unset (&value); - g_value_init (&value, G_TYPE_UINT); - hildon_date_editor_set_year (date_editor, MIN_YEAR); - g_object_get_property (G_OBJECT (date_editor), "year", &value); - fail_if (g_value_get_uint (&value) != MIN_YEAR, - "hildon-date-editor: The returned year is %u and should be %u", - g_value_get_uint (&value), MIN_YEAR); -} -END_TEST - -/* ----- Test case for get_month -----*/ - -/** - * Purpose: test getting a year for regular values for - * hildon_date_editor_get_month - * Cases considered: - * - set month with set_date 30/03/1981 - * - set month with set_month 1 - * - set month with set_property 7 - */ -START_TEST (test_get_month_regular) -{ - guint year, month, day; - GValue value = {0, }; - - year = 1981; - month = 3; - day = 30; - - /* Test 1: Set year with set_date */ - hildon_date_editor_set_date (date_editor, year, month, day); - - fail_if (hildon_date_editor_get_month (date_editor) != month, - "hildon-date-editor: The returned month is %u and should be %u", - hildon_date_editor_get_month (date_editor), month); - - /* Test 2: set month with set_month */ - month = 1; - hildon_date_editor_set_month (date_editor, month); - - fail_if (hildon_date_editor_get_month (date_editor) != month, - "hildon-date-editor: The returned month is %u and should be %u", - hildon_date_editor_get_month (date_editor), month); - - /* Test 3: set month with set_property */ - month = 7; - g_value_init (&value, G_TYPE_UINT); - g_value_set_uint (&value, month); - g_object_set_property (G_OBJECT (date_editor), "month", &value); - - fail_if (hildon_date_editor_get_month (date_editor) != month, - "hildon-date-editor: The returned month is %u and should be %u", - hildon_date_editor_get_month (date_editor), month); -} -END_TEST - -/** - * Purpose: test getting values of the month over the limits for - * hildon_date_editor_get_month - * Cases considered: - * - Get month 12 - * - Get month 1 - */ -START_TEST (test_get_month_limits) -{ - - /* Test 1: Upper limit */ - hildon_date_editor_set_month (date_editor, MAX_MONTH); - - fail_if (hildon_date_editor_get_month (date_editor) != MAX_MONTH, - "hildon-date-editor: get_month failed. The returned month is %u and should be %u", - hildon_date_editor_get_month (date_editor), MAX_MONTH); - - /* Test 2: Lower limit */ - hildon_date_editor_set_month (date_editor, MIN_MONTH); - - fail_if (hildon_date_editor_get_month (date_editor) != MIN_MONTH, - "hildon-date-editor: get_month failed. The returned month is %u and should be %u", - hildon_date_editor_get_month (date_editor), MIN_MONTH); -} -END_TEST - -/** - * Purpose: test getting a month for invalid attributes for - * hildon_date_editor_get_month - * Cases considered: - * - HildonDateEditor is NULL - * - HildonDateEditor is really a GtkHBox - */ -START_TEST (test_get_month_invalid) -{ - guint ret_month; - GtkWidget *aux_object = NULL; - - /* Test 1: Test NULL */ - ret_month = hildon_date_editor_get_month (NULL); - fail_if (ret_month != 0, - "hildon-date-editor: get_month failed. The returned month is %u and should be %u", - ret_month, 0); - - /* Test 2: another object */ - aux_object = gtk_hbox_new (TRUE, 0); - ret_month = hildon_date_editor_get_month ((HildonDateEditor *) (aux_object)); - fail_if (ret_month != 0, - "hildon-date-editor: get_month failed. The returned month is %u and should be %u", - ret_month, 0); - gtk_widget_destroy (GTK_WIDGET(aux_object)); -} -END_TEST - -/* ----- Test case for set_month -----*/ - -/** - * Purpose: test setting regular values for month for - * hildon_date_editor_set_month - * Cases considered: - * - Set month 3 - */ -START_TEST (test_set_month_regular) -{ - guint month; - guint ret_month; - - month = 3; - - /* Test 1: Try month March (3) */ - hildon_date_editor_set_month (date_editor, month); - ret_month = hildon_date_editor_get_month (date_editor); - - fail_if (ret_month != month, - "hildon-date-editor: set_month failed. The returned month is %u and should be %u", - ret_month, month); -} -END_TEST - -/** - * Purpose: test setting values for month over the limits for - * hildon_date_editor_get_month - * Cases considered: - * - Set month 12 - * - Set month 1 - */ -START_TEST (test_set_month_limits) -{ - GValue value = { 0, }; - - /* Test 1: Test upper limit */ - g_value_init (&value, G_TYPE_UINT); - hildon_date_editor_set_month (date_editor, MAX_MONTH); - g_object_get_property (G_OBJECT (date_editor), "month", &value); - fail_if (g_value_get_uint (&value) != MAX_MONTH, - "hildon-date-editor: The returned month is %u and should be %u", - g_value_get_uint (&value), MAX_MONTH); - - /* Test 2: Test lower limit */ - g_value_unset (&value); - g_value_init (&value, G_TYPE_UINT); - hildon_date_editor_set_month (date_editor, MIN_MONTH); - g_object_get_property (G_OBJECT (date_editor), "month", &value); - fail_if (g_value_get_uint (&value) != MIN_MONTH, - "hildon-date-editor: The returned month is %u and should be %u", - g_value_get_uint (&value), MIN_MONTH); -} -END_TEST - -/* ----- Test case for get_day -----*/ - -/** - * Purpose: test getting regular values for day for - * hildon_date_editor_get_day - * Cases considered: - * - Get a day set with set_date 30/03/1981 - * - Get a day set with set_day 6 - * - Get a day set with set_property 10 - */ -START_TEST (test_get_day_regular) -{ - guint year, month, day; - GValue value = {0, }; - - year = 1981; - month = 3; - day = 30; - - /* Test 1: Set day with set_date */ - hildon_date_editor_set_date (date_editor, year, month, day); - - fail_if (hildon_date_editor_get_day (date_editor) != day, - "hildon-date-editor: The returned day is %u and should be %u", - hildon_date_editor_get_day (date_editor), day); - - /* Test 2: set day with set_day */ - day = 6; - hildon_date_editor_set_day (date_editor, day); - - fail_if (hildon_date_editor_get_day (date_editor) != day, - "hildon-date-editor: The returned day is %u and should be %u", - hildon_date_editor_get_day (date_editor), day); - - - /* Test 3: set day with set_property */ - day = 10; - g_value_init (&value, G_TYPE_UINT); - g_value_set_uint (&value, day); - g_object_set_property (G_OBJECT (date_editor), "day", &value); - - fail_if (hildon_date_editor_get_day (date_editor) != day, - "hildon-date-editor: The returned day is %u and should be %u", - hildon_date_editor_get_day (date_editor), day); - -} -END_TEST - -/** - * Purpose: test getting a day set over the limits for - * hildon_date_editor_get_day - * Cases considered: - * - Get day 31 for March - * - Get day 30 for June - * - Get day 29 for February for a leap year - * - Get day 28 for February for a common year - * - Get day 1 - */ -START_TEST (test_get_day_limits) -{ - guint day, month, year; - - year = 1981; - month = 3; - day = 31; - - /* Test 1: 31 of February */ - hildon_date_editor_set_date (date_editor, year, month, day); - fail_if (hildon_date_editor_get_day (date_editor) != day, - "hildon-date-editor: get_day failed. The returned day is %u and should be %u", - hildon_date_editor_get_day (date_editor), day); - - /* Test 2: 30 of February */ - month = 6; - day = 30; - hildon_date_editor_set_date (date_editor, year, month, day); - fail_if (hildon_date_editor_get_day (date_editor) != day, - "hildon-date-editor: get_day failed. The returned day is %u and should be %u", - hildon_date_editor_get_day (date_editor), day); - - /* Test 3: 29 of February */ - year = 1980; - month = 2; - day = 29; - hildon_date_editor_set_date (date_editor, year, month, day); - fail_if (hildon_date_editor_get_day (date_editor) != day, - "hildon-date-editor: get_day failed. The returned day is %u and should be %u", - hildon_date_editor_get_day (date_editor), day); - - /* Test 3: 28 of February */ - year = 1981; - month = 2; - day = 28; - hildon_date_editor_set_date (date_editor, year, month, day); - fail_if (hildon_date_editor_get_day (date_editor) != day, - "hildon-date-editor: get_day failed. The returned day is %u and should be %u", - hildon_date_editor_get_day (date_editor), day); - - /* Test 5: day 1 */ - hildon_date_editor_set_day (date_editor, 1); - - fail_if (hildon_date_editor_get_day (date_editor) != 1, - "hildon-date-editor: get_day failed. The returned day is %u and should be %u", - hildon_date_editor_get_day (date_editor), 1); -} -END_TEST - -/** - * Purpose: test getting a day with invalid attributes for - * hildon_date_editor_get_day - * Cases considered: - * - HildonDateEditor is NULL - * - HildonDateEditor is really a GtkHBox - */ -START_TEST (test_get_day_invalid) -{ - guint ret_year; - GtkWidget *aux_object = NULL; - - /* Test 1: Test NULL */ - ret_year = hildon_date_editor_get_year (NULL); - fail_if (ret_year != 0, - "hildon-date-editor: get_year failed. The returned year is %u and should be %u", - ret_year, 0); - - /* Test 2: another object */ - aux_object = gtk_hbox_new (TRUE, 0); - ret_year = hildon_date_editor_get_year ((HildonDateEditor *) aux_object); - fail_if (ret_year != 0, - "hildon-date-editor: get_year failed. The returned year is %u and should be %u", - ret_year, 0); - gtk_widget_destroy (GTK_WIDGET(aux_object)); -} -END_TEST - -/* ----- Test case for set_day -----*/ - -/** - * Purpose: test setting a regular value for day for - * hildon_date_editor_get_day - * Cases considered: - * - Set day 30 - */ -START_TEST (test_set_day_regular) -{ - guint day; - guint ret_day; - - day = 25; - - /* Test 1: Try day 30 */ - hildon_date_editor_set_day (date_editor, day); - ret_day = hildon_date_editor_get_day (date_editor); - - fail_if (ret_day != day, - "hildon-date-editor: set_day failed. The returned day is %u and should be %u", - ret_day, day); -} -END_TEST - -/** - * Purpose: test seeting a day over the limits for - * hildon_date_editor_get_day - * Cases considered: - * - Set day 31 - * - Set day 30 - * - Set day 29 - * - Set day 28 - * - Set day 1 - */ -START_TEST (test_set_day_limits) -{ - guint day, year, month; - GValue value = { 0, }; - - year = 1981; - month = 3; - day = 31; - - /* Set init date */ - hildon_date_editor_set_date (date_editor, year, month, MIN_DAY); - - /* Test 1: Test 31/03 */ - g_value_init (&value, G_TYPE_UINT); - hildon_date_editor_set_day (date_editor, day); - g_object_get_property (G_OBJECT (date_editor), "day", &value); - fail_if (g_value_get_uint (&value) != day, - "hildon-date-editor: The returned day is %u and should be %u", - g_value_get_uint (&value), day); - - /* Test 2: Test 30/06 */ - month = 6; - day = 30; - hildon_date_editor_set_date (date_editor, year, month, 1); - g_value_unset (&value); - g_value_init (&value, G_TYPE_UINT); - hildon_date_editor_set_day (date_editor, day); - g_object_get_property (G_OBJECT (date_editor), "day", &value); - fail_if (g_value_get_uint (&value) != day, - "hildon-date-editor: The returned day is %u and should be %u", - g_value_get_uint (&value), day); - - /* Test 3: Test 29/02/1980 */ - year = 1980; - month = 2; - day = 29; - hildon_date_editor_set_date (date_editor, year, month, 1); - g_value_unset (&value); - g_value_init (&value, G_TYPE_UINT); - hildon_date_editor_set_day (date_editor, day); - g_object_get_property (G_OBJECT (date_editor), "day", &value); - fail_if (g_value_get_uint (&value) != day, - "hildon-date-editor: The returned day is %u and should be %u", - g_value_get_uint (&value), day); - - /* Test 4: Test 28/02/1981 */ - year = 1981; - month = 2; - day = 28; - hildon_date_editor_set_date (date_editor, year, month, 1); - g_value_unset (&value); - g_value_init (&value, G_TYPE_UINT); - hildon_date_editor_set_day (date_editor, day); - g_object_get_property (G_OBJECT (date_editor), "day", &value); - fail_if (g_value_get_uint (&value) != day, - "hildon-date-editor: The returned day is %u and should be %u", - g_value_get_uint (&value), day); - - /* Test 5: Test 1/02/1980 */ - year = 1980; - month = 2; - day = 1; - hildon_date_editor_set_date (date_editor, year, month, 10); - g_value_unset (&value); - g_value_init (&value, G_TYPE_UINT); - hildon_date_editor_set_day (date_editor, day); - g_object_get_property (G_OBJECT (date_editor), "day", &value); - fail_if (g_value_get_uint (&value) != day, - "hildon-date-editor: The returned day is %u and should be %u", - g_value_get_uint (&value), day); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_date_editor_suite(void) -{ - /* Create the suite */ - Suite *s = suite_create("HildonDateEditor"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_date"); - TCase *tc2 = tcase_create("get_date"); - TCase *tc3 = tcase_create("get_year"); - TCase *tc4 = tcase_create("set_year"); - TCase *tc5 = tcase_create("get_month"); - TCase *tc6 = tcase_create("set_month"); - TCase *tc7 = tcase_create("get_day"); - TCase *tc8 = tcase_create("set_day"); - - /* Create test case for set_date and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_date_editor, fx_teardown_default_date_editor); - tcase_add_test(tc1, test_set_date_regular); - tcase_add_test(tc1, test_set_date_limits); - tcase_add_test(tc1, test_set_date_invalid); - suite_add_tcase (s, tc1); - - /* Create test case for get_date and add it to the suite */ - tcase_add_checked_fixture(tc2, fx_setup_default_date_editor, fx_teardown_default_date_editor); - tcase_add_test(tc2, test_get_date_regular); - tcase_add_test(tc2, test_get_date_invalid); - suite_add_tcase (s, tc2); - - /* Create test case for get_year and add it to the suite */ - tcase_add_checked_fixture(tc3, fx_setup_default_date_editor, fx_teardown_default_date_editor); - tcase_add_test(tc3, test_get_year_regular); - tcase_add_test(tc3, test_get_year_limits); - tcase_add_test(tc3, test_get_year_invalid); - suite_add_tcase (s, tc3); - - /* Create test case for set_year and add it to the suite */ - tcase_add_checked_fixture(tc4, fx_setup_default_date_editor, fx_teardown_default_date_editor); - tcase_add_test(tc4, test_set_year_regular); - tcase_add_test(tc4, test_set_year_limits); - suite_add_tcase (s, tc4); - - /* Create test case for get_month and add it to the suite */ - tcase_add_checked_fixture(tc5, fx_setup_default_date_editor, fx_teardown_default_date_editor); - tcase_add_test(tc5, test_get_month_regular); - tcase_add_test(tc5, test_get_month_limits); - tcase_add_test(tc5, test_get_month_invalid); - suite_add_tcase (s, tc5); - - /* Create test case for set_month and add it to the suite */ - tcase_add_checked_fixture(tc6, fx_setup_default_date_editor, fx_teardown_default_date_editor); - tcase_add_test(tc6, test_set_month_regular); - tcase_add_test(tc6, test_set_month_limits); - suite_add_tcase (s, tc6); - - /* Create test case for get_day and add it to the suite */ - tcase_add_checked_fixture(tc7, fx_setup_default_date_editor, fx_teardown_default_date_editor); - tcase_add_test(tc7, test_get_day_regular); - tcase_add_test(tc7, test_get_day_limits); - tcase_add_test(tc7, test_get_day_invalid); - suite_add_tcase (s, tc7); - - /* Create test case for set_day and add it to the suite */ - tcase_add_checked_fixture(tc8, fx_setup_default_date_editor, fx_teardown_default_date_editor); - tcase_add_test(tc8, test_set_day_regular); - tcase_add_test(tc8, test_set_day_limits); - suite_add_tcase (s, tc8); - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-font-selection-dialog.c b/tests/check-hildon-font-selection-dialog.c deleted file mode 100644 index c71915a..0000000 --- a/tests/check-hildon-font-selection-dialog.c +++ /dev/null @@ -1,478 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <glib/gprintf.h> -#include <string.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-font-selection-dialog.h> - -#define PREVIEW_TEXT TEST_STRING -#define DEFAULT_FONT_FAMILY "Sans" - -static const guint16 N_FONT_SIZES = 7; -static const guint16 FONT_SIZES[] = - { - 6, 8, 10, 12, 16, 24, 32 - }; - -/* -------------------- Fixtures -------------------- */ - -static HildonFontSelectionDialog *font_selection_dialog = NULL; -static GtkWidget *showed_window = NULL; - -static void -fx_setup_default_font_selection_dialog () -{ - int argc = 0; - gtk_init(&argc, NULL); - - showed_window = create_test_window(); - - - font_selection_dialog = HILDON_FONT_SELECTION_DIALOG(hildon_font_selection_dialog_new(GTK_WINDOW(showed_window), "Font setup")); - - /* Check font selection dialog object has been created properly */ - fail_if(!HILDON_IS_FONT_SELECTION_DIALOG(font_selection_dialog), - "hildon-font-selection-dialog: Creation failed."); - - show_test_window(GTK_WIDGET(showed_window)); - - show_test_window(GTK_WIDGET(font_selection_dialog)); - -} - -static void -fx_teardown_default_font_selection_dialog () -{ - - gtk_widget_destroy(GTK_WIDGET(font_selection_dialog)); - - gtk_widget_destroy(GTK_WIDGET(showed_window)); - -} - -/* -------------------- Helpers -------------------- */ - -static int -helper_cmp_families(const void *a, const void *b) -{ - const char *a_name = - pango_font_family_get_name(*(PangoFontFamily **) a); - const char *b_name = - pango_font_family_get_name(*(PangoFontFamily **) b); - - return g_utf8_collate(a_name, b_name); -} - -static void -helper_get_available_fonts(HildonFontSelectionDialog *fsd, - PangoFontFamily ***families, - gint *n_families) - -{ - pango_context_list_families(gtk_widget_get_pango_context(GTK_WIDGET(fsd)), - families, - n_families); - - qsort(*families, *n_families, sizeof(PangoFontFamily *), helper_cmp_families); -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set/get_preview_text ----- */ - -/** - * Purpose: Check set and get of a valid preview text - * Cases considered: - * - Set and get of a preview text - */ -START_TEST (test_set_get_preview_text_regular) -{ - gchar *ret_preview_text; - - /* Test1: set and get a preview text */ - hildon_font_selection_dialog_set_preview_text(font_selection_dialog, PREVIEW_TEXT); - ret_preview_text = hildon_font_selection_dialog_get_preview_text(font_selection_dialog); - fail_if(strcmp(PREVIEW_TEXT, ret_preview_text) != 0, - "hildon-font-selection-dialog: Called set_previex_text with \"%s\", but get_preview_text returned \"%s\"", - PREVIEW_TEXT, ret_preview_text); - g_free(ret_preview_text); -} -END_TEST - -/** - * Purpose: Check handling of invalid values - * Cases considered: - * - Set empty preview text - * - Set a NULL preview text - * - Set with NULL object - * - Set with NULL object - */ -START_TEST (test_set_get_preview_text_invalid) -{ - gchar *ret_preview_text; - - /* Test1: Set a NULL preview text */ - hildon_font_selection_dialog_set_preview_text(font_selection_dialog, NULL); - ret_preview_text = hildon_font_selection_dialog_get_preview_text(font_selection_dialog); - fail_if(ret_preview_text == NULL, - "hildon-font-selection-dialog: Call to set_preview_text with a NULL text is allowed"); - g_free(ret_preview_text); - - /* Test2: Set an empty preview text */ - hildon_font_selection_dialog_set_preview_text(font_selection_dialog, ""); - ret_preview_text = hildon_font_selection_dialog_get_preview_text(font_selection_dialog); - fail_if(strcmp("", ret_preview_text) != 0, - "hildon-font-selection-dialog: Call to set_preview_text with an empty text is allowed"); - g_free(ret_preview_text); - - /* Test3: Set with NULL object */ - hildon_font_selection_dialog_set_preview_text(NULL, PREVIEW_TEXT); - - /* Test4: Get with NULL object */ - hildon_font_selection_dialog_get_preview_text(NULL); -} -END_TEST - -/* ----- Test case for set/get property "family" ----- */ - -/** - * Purpose: Check handling of regular values - * Cases considered: - * - Set and get a font from the middle of the available fonts list - */ -START_TEST (test_set_get_property_family_regular) -{ - PangoFontFamily **families; - gint n_families; - GValue value = {0,}; - GValue ret_value = {0,}; - - helper_get_available_fonts(font_selection_dialog, &families, &n_families); - fail_if (n_families <= 0, "hildon-font-selection-dialog: No available fonts"); - - /* Test1: set and get a font family */ - g_value_init(&value, G_TYPE_STRING); - g_value_init(&ret_value, G_TYPE_STRING); - g_value_set_string(&value, pango_font_family_get_name(families[n_families/2])); - g_object_set_property(G_OBJECT(font_selection_dialog), "family", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "family", &ret_value); - fail_if(strcmp(g_value_get_string(&value), g_value_get_string(&ret_value)) != 0, - "hildon-font-selection-dialog: set property \"family\" to value \"%s\", but get property returned value \"%s\"", - g_value_get_string(&value), g_value_get_string(&ret_value)); -} -END_TEST - -/** - * Purpose: Check handling of limit values - * Cases considered: - * - Set and get first font of the available fonts list - * - Set and get last font of the available fonts list - */ -START_TEST (test_set_get_property_family_limits) -{ - PangoFontFamily **families; - gint n_families; - GValue value = {0,}; - GValue ret_value = {0,}; - - helper_get_available_fonts(font_selection_dialog, &families, &n_families); - fail_if (n_families <= 0, "hildon-font-selection-dialog: No available fonts"); - - /* Test1: Test first font in the list */ - g_value_init(&value, G_TYPE_STRING); - g_value_init(&ret_value, G_TYPE_STRING); - g_value_set_string(&value, pango_font_family_get_name(families[0])); - g_object_set_property(G_OBJECT(font_selection_dialog), "family", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "family", &ret_value); - fail_if(strcmp(g_value_get_string(&value), g_value_get_string(&ret_value)) != 0, - "hildon-font-selection-dialog: set property \"family\" to value \"%s\", but get property returned value \"%s\"", - g_value_get_string(&value), g_value_get_string(&ret_value)); - - /* Test2: Test last font in the list */ - g_value_set_string(&value, pango_font_family_get_name(families[n_families-1])); - g_object_set_property(G_OBJECT(font_selection_dialog), "family", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "family", &ret_value); - fail_if(strcmp(g_value_get_string(&value), g_value_get_string(&ret_value)) != 0, - "hildon-font-selection-dialog: set property \"family\" to value \"%s\", but get property returned value \"%s\"", - g_value_get_string(&value), g_value_get_string(&ret_value)); -} -END_TEST - -/** - * Purpose: Check handling of invalid values - * Cases considered: - * - Set a non existing font - * - Set a NULL font - */ -START_TEST (test_set_get_property_family_invalid) -{ - GValue value = {0,}; - GValue ret_value = {0,}; - - /* Test1: Set non existing font */ - g_value_init(&value, G_TYPE_STRING); - g_value_init(&ret_value, G_TYPE_STRING); - g_value_set_string(&value, "-- invalid font name --"); - g_object_set_property(G_OBJECT(font_selection_dialog), "family", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "family", &ret_value); - fail_if(strcmp(DEFAULT_FONT_FAMILY, g_value_get_string(&ret_value)) != 0, - "hildon-font-selection-dialog: set property \"family\" to invalid font name \"%s\", but get property returned value \"%s\" instead of \"%s\"", - g_value_get_string(&value), g_value_get_string(&ret_value), DEFAULT_FONT_FAMILY); - - /* Test2: Set NULL font */ - g_value_reset (&ret_value); - g_value_reset (&value); - g_value_set_string(&value, NULL); - g_object_set_property(G_OBJECT(font_selection_dialog), "family", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "family", &ret_value); - fail_if(strcmp(DEFAULT_FONT_FAMILY, g_value_get_string(&ret_value)) != 0, - "hildon-font-selection-dialog: set property \"family\" to NULL, but get property returned value \"%s\" instead of \"%s\"", - g_value_get_string(&ret_value), DEFAULT_FONT_FAMILY); -} -END_TEST - -/* ----- Test case for set/get property "family-set" ----- */ - -/** - * Purpose: Check set and get of valid values - * Cases considered: - * - Get returns FALSE when no font is selected. - * - Get returns TRUE when a font has been selected. - * - Set and get of value TRUE once a font has been selected - * - Set and get of value FALSE - */ -START_TEST (test_set_get_property_family_set_regular) -{ - PangoFontFamily **families; - gint n_families; - GValue value = {0,}; - GValue ret_value = {0,}; - GValue family_value = {0,}; - - helper_get_available_fonts(font_selection_dialog, &families, &n_families); - fail_if (n_families <= 0, "hildon-font-selection-dialog: No available fonts"); - - g_value_init(&value, G_TYPE_BOOLEAN); - g_value_init(&ret_value, G_TYPE_BOOLEAN); - g_value_init(&family_value, G_TYPE_STRING); - - /* Test1: Check get value returns FALSE when no font is selected */ - g_object_get_property(G_OBJECT(font_selection_dialog), "family-set", &ret_value); - if (g_value_get_boolean(&ret_value) == FALSE) - { - g_object_get_property(G_OBJECT(font_selection_dialog), "family", &family_value); - fail_if(strcmp(DEFAULT_FONT_FAMILY, g_value_get_string(&family_value)) != 0, - "hildon-font-selection-dialog: After dialog creation, get value of property \"family-set\" returns FALSE, but get value of property \"family\" is \"%s\" instead of \"%s\"", - g_value_get_string(&family_value), DEFAULT_FONT_FAMILY); - } - - /* Test2: Check get value returns TRUE when a font has been selected */ - g_value_set_string(&family_value, pango_font_family_get_name(families[0])); - g_object_set_property(G_OBJECT(font_selection_dialog), "family", &family_value); - g_object_get_property(G_OBJECT(font_selection_dialog), "family-set", &ret_value); - fail_if(g_value_get_boolean(&ret_value) != TRUE, - "hildon-font-selection-dialog: Set a valid font for property \"family\", but get property \"family-set\" returned FALSE"); - - /* Test3: Check set value to TRUE */ - g_value_set_boolean(&value, TRUE); - g_object_get_property(G_OBJECT(font_selection_dialog), "family-set", &ret_value); - fail_if(g_value_get_boolean(&ret_value) != TRUE, - "hildon-font-selection-dialog: Set property \"family-set\" to TRUE once a valid font has been selected, but get_property returned FALSE"); - - /* Test4: Check set value to FALSE */ - g_value_set_boolean(&value, FALSE); - g_object_set_property(G_OBJECT(font_selection_dialog), "family-set", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "family-set", &ret_value); - fail_if(g_value_get_boolean(&value) != g_value_get_boolean(&ret_value), - "hildon-font-selection-dialog: Set property \"family-set\" to FALSE, but get_property returned TRUE"); - g_object_get_property(G_OBJECT(font_selection_dialog), "family", &family_value); - fail_if(strcmp(DEFAULT_FONT_FAMILY, g_value_get_string(&family_value)) != 0, - "hildon-font-selection-dialog: Set property \"family-set\" to FALSE, but get of propery \"family\" returns \"%s\" instead of \"%s\"", - g_value_get_string(&family_value), DEFAULT_FONT_FAMILY); -} -END_TEST - -/* ----- Test case for set/get property "size" ----- */ - -/** - * Purpose: Check set and get of valid values - * Cases considered: - * - Set a font size from the middle of the available sizes list - */ -START_TEST (test_set_get_property_size_regular) -{ - gint font_size; - GValue value = {0,}; - GValue ret_value = {0,}; - - g_value_init(&value, G_TYPE_INT); - g_value_init(&ret_value, G_TYPE_INT); - - /* Test1: set a valid font size */ - font_size = FONT_SIZES[N_FONT_SIZES/2]; - g_value_set_int(&value, font_size); - g_object_set_property(G_OBJECT(font_selection_dialog), "size", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "size", &ret_value); - fail_if(g_value_get_int(&ret_value) != font_size, - "hildon-font-selection-dialog: Set property \"size\" to %d, but get property returned \"%d\"", - font_size, g_value_get_int(&ret_value)); -} -END_TEST - -/** - * Purpose: Check set and get of limit values - * Cases considered: - * - Set first font size in the available sizes list - * - Set last font size in the available sizes list - */ -START_TEST (test_set_get_property_size_limits) -{ - gint font_size; - GValue value = {0,}; - GValue ret_value = {0,}; - - g_value_init(&value, G_TYPE_INT); - g_value_init(&ret_value, G_TYPE_INT); - - /* Test1: set first font size */ - font_size = FONT_SIZES[0]; - g_value_set_int(&value, font_size); - g_object_set_property(G_OBJECT(font_selection_dialog), "size", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "size", &ret_value); - fail_if(g_value_get_int(&ret_value) != font_size, - "hildon-font-selection-dialog: Set property \"size\" to %d, but get property returned \"%d\"", - font_size, g_value_get_int(&ret_value)); - - /* Test2: set last font size */ - font_size = FONT_SIZES[N_FONT_SIZES-1]; - g_value_set_int(&value, font_size); - g_object_set_property(G_OBJECT(font_selection_dialog), "size", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "size", &ret_value); - fail_if(g_value_get_int(&ret_value) != font_size, - "hildon-font-selection-dialog: Set property \"size\" to %d, but get property returned \"%d\"", - font_size, g_value_get_int(&ret_value)); -} -END_TEST - -/** - * Purpose: Check set and get of invalid values - * Cases considered: - * - Set negative size - * - Set a positive size that is not in the available sizes list - * - Set a positive size over the maximum allowed for the property - */ -START_TEST (test_set_get_property_size_invalid) -{ - gint font_size; - gint default_size; - GValue value = {0,}; - GValue ret_value = {0,}; - - g_value_init(&value, G_TYPE_INT); - g_value_init(&ret_value, G_TYPE_INT); - - default_size = 8; - g_value_set_int(&value, default_size); - g_object_set_property(G_OBJECT(font_selection_dialog), "size", &value); - - /* Test1: Set negative value */ - font_size = -5; - g_value_set_int(&value, font_size); - g_object_set_property(G_OBJECT(font_selection_dialog), "size", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "size", &ret_value); - fail_if(g_value_get_int(&ret_value) != default_size, - "hildon-font-selection-dialog: Set property \"size\" to invalid %d, but get property returned \"%d\" instead of previous valid value \"%d\"", - font_size, g_value_get_int(&ret_value), default_size); - - /* Test2: Set a positive that is not in the available list */ - font_size = 17; - g_value_set_int(&value, font_size); - g_object_set_property(G_OBJECT(font_selection_dialog), "size", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "size", &ret_value); - fail_if(g_value_get_int(&ret_value) != default_size, - "hildon-font-selection-dialog: Set property \"size\" to invalid %d, but get property returned \"%d\" instead of previous valid value \"%d\"", - font_size, g_value_get_int(&ret_value), default_size); - - /* Test3: Set a positive value over the maximum allowed */ - font_size = 112; - g_value_set_int(&value, font_size); - g_object_set_property(G_OBJECT(font_selection_dialog), "size", &value); - g_object_get_property(G_OBJECT(font_selection_dialog), "size", &ret_value); - fail_if(g_value_get_int(&ret_value) != default_size, - "hildon-font-selection-dialog: Set property \"size\" to invalid %d, but get property returned \"%d\" instead of previous valid value \"%d\"", - font_size, g_value_get_int(&ret_value), default_size); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_font_selection_dialog_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonFontSelectionDialog"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_get_preview_text"); - TCase *tc2 = tcase_create("set_get_property_family"); - TCase *tc3 = tcase_create("set_get_property_family_set"); - TCase *tc4 = tcase_create("set_get_property_size"); - - /* Create test case for set/get_preview_text and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_font_selection_dialog, - fx_teardown_default_font_selection_dialog); - tcase_add_test(tc1, test_set_get_preview_text_regular); - tcase_add_test(tc1, test_set_get_preview_text_invalid); - suite_add_tcase(s, tc1); - - /* Create test case for set/get property "family" and add it to the suite */ - tcase_add_checked_fixture(tc2, fx_setup_default_font_selection_dialog, - fx_teardown_default_font_selection_dialog); - tcase_add_test(tc2, test_set_get_property_family_regular); - tcase_add_test(tc2, test_set_get_property_family_limits); - tcase_add_test(tc2, test_set_get_property_family_invalid); - suite_add_tcase(s, tc2); - - /* Create test case for set/get property "family-set" and add it to the suite */ - tcase_add_checked_fixture(tc3, fx_setup_default_font_selection_dialog, - fx_teardown_default_font_selection_dialog); - tcase_add_test(tc3, test_set_get_property_family_set_regular); - suite_add_tcase(s, tc3); - - /* Create test case for set/get property "size" and add it to the suite */ - tcase_add_checked_fixture(tc4, fx_setup_default_font_selection_dialog, - fx_teardown_default_font_selection_dialog); - tcase_add_test(tc4, test_set_get_property_size_regular); - tcase_add_test(tc4, test_set_get_property_size_limits); - tcase_add_test(tc4, test_set_get_property_size_invalid); - suite_add_tcase(s, tc4); - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-get-password-dialog.c b/tests/check-hildon-get-password-dialog.c deleted file mode 100644 index 8349b1e..0000000 --- a/tests/check-hildon-get-password-dialog.c +++ /dev/null @@ -1,465 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <string.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include "test_suites.h" -#include "check_utils.h" -#include <hildon/hildon-get-password-dialog.h> - -/* -------------------- Fixtures -------------------- */ - -static HildonGetPasswordDialog *get_password_dialog = NULL; -static GtkWindow * gpd_window = NULL; - -static void -fx_setup_default_get_password_dialog () -{ - int argc = 0; - - gtk_init(&argc, NULL); - - gpd_window = GTK_WINDOW(create_test_window()); - - /* Check the auxiliary window is being created properly */ - fail_if (!GTK_IS_WINDOW (gpd_window), - "hildon-get-password-dialog: Window creation failed."); - - get_password_dialog = HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new(gpd_window, TRUE)); - /* Check get password dialog object has been created properly */ - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog), - "hildon-get-password-dialog: Creation failed."); - - show_test_window(GTK_WIDGET(gpd_window)); - - show_test_window(GTK_WIDGET(get_password_dialog)); - -} - -static void -fx_teardown_default_get_password_dialog () -{ - gtk_widget_destroy(GTK_WIDGET(get_password_dialog)); - - gtk_widget_destroy(GTK_WIDGET(gpd_window)); -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for hildon_get_password_dialog_new_with_default -----*/ - -/** - * Purpose: Check that regular password values are set and get properly. - * Cases considered: - * - Create new get password dialog with "test_password" password by default. - * - Create new get password dialog with "" password by default. - * - Create new get password dialog with "1234567890" password by default. - * - Create new get password dialog with TEST_STRING password by default - */ -START_TEST (test_new_with_default_regular) -{ - const gchar * default_password=NULL; - const gchar * ret_password; - HildonGetPasswordDialog * default_get_password_dialog; - - /* Test 1: Create new dialog with password "test_password" by default */ - default_password="test_password"; - default_get_password_dialog = - HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE)); - fail_if (!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog), - "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default"); - - ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog); - fail_if (strcmp (default_password,ret_password) != 0, - "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password); - gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog)); - - /* Test 2: Create new dialog with password "" by default */ - default_password=""; - default_get_password_dialog = - HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE)); - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog), - "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default"); - - ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog); - fail_if (strcmp (default_password,ret_password) != 0, - "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password); - - gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog)); - - /* Test 3: Create new dialog with password "1234567890" by default */ - default_password="1234567890"; - - default_get_password_dialog = - HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE)); - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog), - "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default"); - - ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog); - fail_if(strcmp (default_password,ret_password)!=0, - "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password); - - gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog)); - - /* Test 4: Create new dialog with password TEST_STRING by default */ - default_password=TEST_STRING; - - default_get_password_dialog = - HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE)); - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog), - "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default"); - - ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog); - fail_if (strcmp (default_password,ret_password) != 0, - "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password); - - gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog)); -} -END_TEST - -/** - * Purpose: Check that invalid password values are set and get properly. - * Cases considered: - * - Create new NULL get password dialog. - * - Create new dialog with NULL window by default - */ -START_TEST (test_new_with_default_invalid) -{ - const gchar * default_password=""; - const gchar * ret_password; - HildonGetPasswordDialog * default_get_password_dialog; - - /* Check get password dialog object has been created properly */ - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog), - "hildon-get-password-dialog: Creation failed."); - fail_if (!GTK_IS_WINDOW (gpd_window), - "hildon-get-password-dialog: Window creation failed."); - - /* Test 1: Create new dialog with NULL password by default */ - default_password=NULL; - default_get_password_dialog = - HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE)); - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog), - "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default"); - - ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog); - fail_if(strcmp ("",ret_password) != 0, - "hildon-get-password-dialog: Error setting null password. Returned password is \"%s\"",ret_password); - - gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog)); - - /* Test 2: Create new dialog with NULL window by default */ - default_get_password_dialog = - HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(NULL,default_password,FALSE)); - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog), - "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default"); - - ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog); - fail_if (ret_password == NULL, - "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password); - - gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog)); -} -END_TEST - -/** - * Purpose: Check that regular "max characters" values are set and get properly. - * Cases considered: - * - Set max characters to 10. - * - Set max characters to G_MAXUINT16+1. - * - */ -START_TEST (test_set_max_characters_regular) -{ - gint max_chars; - gint ret_max_chars; - GValue value={0, }; - - /* Check get password dialog object has been created properly */ - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog), - "hildon-get-password-dialog: Creation failed."); - fail_if (!GTK_IS_WINDOW (gpd_window), - "hildon-get-password-dialog: Window creation failed."); - - g_value_init (&value, G_TYPE_INT); - - /* Test 1: Set max characters to 10 */ - max_chars = 10; - hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars); - g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value); - ret_max_chars = g_value_get_int (&value); - - fail_if(ret_max_chars!=max_chars, - "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars); - - g_value_unset (&value); - - /* Test 2: Set max characters to G_MAXUINT16+1 */ - g_value_init (&value, G_TYPE_INT); - max_chars = G_MAXUINT16+1; - hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars); - g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value); - ret_max_chars = g_value_get_int (&value); - - fail_if(ret_max_chars!=G_MAXUINT16, - "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars); - - g_value_unset (&value); -} -END_TEST - -/** - * Purpose: Check that limits "max characters" values are set and get properly. - * Cases considered: - * - Set max characters to 1. - * - Set max characters to G_MAXINT. - */ -START_TEST (test_set_max_characters_limits) -{ - gint max_chars; - gint ret_max_chars; - GValue value={0, }; - - /* Check get password dialog object has been created properly */ - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog), - "hildon-get-password-dialog: Creation failed."); - fail_if (!GTK_IS_WINDOW (gpd_window), - "hildon-get-password-dialog: Window creation failed."); - - g_value_init (&value, G_TYPE_INT); - - /* Test 1: Set max characters to 1 */ - max_chars = 1; - hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars); - g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value); - ret_max_chars = g_value_get_int (&value); - - fail_if(ret_max_chars!=max_chars, - "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars); - - g_value_unset (&value); - - /* Test 2: Set max characters to G_MAXINT */ - g_value_init (&value, G_TYPE_INT); - max_chars = G_MAXINT; - hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars); - g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value); - ret_max_chars = g_value_get_int (&value); - - fail_if(ret_max_chars!=G_MAXUINT16, - "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %u",max_chars,ret_max_chars); - - g_value_unset (&value); -} -END_TEST - -/** - * Purpose: Check that limits "max characters" values are set and get properly. - * Cases considered: - * - Set max characters to 0. - * - Set max characters to -1. - * - Set max characters on NULL object. - */ -START_TEST (test_set_max_characters_invalid) -{ - gint max_chars; - gint ret_max_chars; - GValue value={0, }; - - /* Check get password dialog object has been created properly */ - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog), - "hildon-get-password-dialog: Creation failed."); - fail_if (!GTK_IS_WINDOW (gpd_window), - "hildon-get-password-dialog: Window creation failed."); - - g_value_init (&value, G_TYPE_INT); - - /* Test 1: Set max characters to 0 */ - max_chars = 0; - hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars); - g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value); - ret_max_chars = g_value_get_int (&value); - - fail_if(ret_max_chars!=max_chars, - "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars); - - g_value_unset (&value); - - /* Test 2: Set max characters to -1 */ - g_value_init (&value, G_TYPE_INT); - max_chars = -1; - hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars); - g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value); - ret_max_chars = g_value_get_int (&value); - - fail_if(ret_max_chars!=0, - "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i and expected is 0",max_chars,ret_max_chars); - g_value_unset (&value); - - /* Test 2: Set max characters on NULL object */ - max_chars = 1; - hildon_get_password_dialog_set_max_characters(NULL,max_chars); -} -END_TEST - -/** - * Purpose: Check that regular password values are get properly. - * Cases considered: - * - Get password "test_password" set by g_object_set_property. - * - Get password "01234567890" set by g_object_set_property. - * - Get password TEST_STRING set by g_object_set_property. - * - Get password "" set by set by g_object_set_property. - */ -START_TEST (test_get_password_regular) -{ - const gchar * default_password="test_password"; - const gchar * ret_password; - GValue value={0, }; - - /* Check get password dialog object has been created properly */ - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog), - "hildon-get-password-dialog: Creation failed."); - fail_if (!GTK_IS_WINDOW (gpd_window), - "hildon-get-password-dialog: Window creation failed."); - - /* Test 1: Get password "test_password" set by g_object_set_property. */ - g_value_init (&value, G_TYPE_STRING); - g_value_set_string(&value,default_password); - g_object_set_property(G_OBJECT (get_password_dialog),"password",&value); - g_value_unset (&value); - - ret_password = hildon_get_password_dialog_get_password(get_password_dialog); - fail_if(strcmp (default_password,ret_password)!=0, - "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password); - - /* Test 2: Get password "01234567890" set by g_object_set_property. */ - default_password = "01234567890"; - - g_value_init (&value, G_TYPE_STRING); - g_value_set_string(&value,default_password); - g_object_set_property(G_OBJECT (get_password_dialog),"password",&value); - g_value_unset (&value); - - ret_password = hildon_get_password_dialog_get_password(get_password_dialog); - fail_if(strcmp (default_password,ret_password)!=0, - "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password); - - /* Test 3: Get password TEST_STRING set by g_object_set_property. */ - default_password = TEST_STRING; - - g_value_init (&value, G_TYPE_STRING); - g_value_set_string(&value,default_password); - g_object_set_property(G_OBJECT (get_password_dialog),"password",&value); - g_value_unset (&value); - - ret_password = hildon_get_password_dialog_get_password(get_password_dialog); - fail_if(strcmp (default_password,ret_password)!=0, - "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password); - - /* Test 4: Get password "" set by g_object_set_property. */ - default_password = ""; - - g_value_init (&value, G_TYPE_STRING); - g_value_set_string(&value,default_password); - g_object_set_property(G_OBJECT (get_password_dialog),"password",&value); - g_value_unset (&value); - - ret_password = hildon_get_password_dialog_get_password(get_password_dialog); - fail_if(strcmp (default_password,ret_password)!=0, - "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password); -} -END_TEST - -/** - * Purpose: Check that limit password values are get properly. - * Cases considered: - * - Get empty password set by g_object_set_property with NULL value. - * - Get password from NULL object. - * - */ -START_TEST (test_get_password_invalid) -{ - const gchar * default_password=NULL; - const gchar * ret_password; - GValue value={0, }; - - /* Check get password dialog object has been created properly */ - fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog), - "hildon-get-password-dialog: Creation failed."); - fail_if (!GTK_IS_WINDOW (gpd_window), - "hildon-get-password-dialog: Window creation failed."); - - /* Test 1: Get password NULL set by g_object_set_property. */ - default_password = NULL; - g_value_init (&value, G_TYPE_STRING); - g_value_set_string(&value,default_password); - g_object_set_property(G_OBJECT (get_password_dialog),"password",&value); - g_value_unset (&value); - - ret_password = hildon_get_password_dialog_get_password(get_password_dialog); - fail_if(strcmp(ret_password,"")!=0, - "hildon-get-password-dialog: Returned password is not empty (%s)",ret_password); - - /* Test 2: Get password from NULL object. */ - ret_password = hildon_get_password_dialog_get_password(NULL); -} -END_TEST - - -/* ---------- Suite creation ---------- */ -Suite *create_hildon_get_password_dialog_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonGetPasswordDialog"); - - /* Create test cases */ - TCase *tc1 = tcase_create("new_with_default"); - TCase *tc2 = tcase_create("set_max_characters"); - TCase *tc3 = tcase_create("get_password"); - - /* Create test case for hildon_get_password_dialog_new_with_default and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_get_password_dialog, fx_teardown_default_get_password_dialog); - tcase_add_test(tc1, test_new_with_default_regular); - tcase_add_test(tc1, test_new_with_default_invalid); - suite_add_tcase (s, tc1); - - /* Create test case for hildon_get_password_dialog_set_max_characters and add it to the suite */ - tcase_add_checked_fixture(tc2, fx_setup_default_get_password_dialog, fx_teardown_default_get_password_dialog); - tcase_add_test(tc2, test_set_max_characters_regular); - tcase_add_test(tc2, test_set_max_characters_limits); - tcase_add_test(tc2, test_set_max_characters_invalid); - suite_add_tcase (s, tc2); - - /* Create test case for hildon_get_password_dialog_get_password and add it to the suite */ - tcase_add_checked_fixture(tc3, fx_setup_default_get_password_dialog, fx_teardown_default_get_password_dialog); - tcase_add_test(tc3, test_get_password_regular); - tcase_add_test(tc3, test_get_password_invalid); - suite_add_tcase (s, tc3); - - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-note.c b/tests/check-hildon-note.c index 1d4dc47..b03dd6c 100644 --- a/tests/check-hildon-note.c +++ b/tests/check-hildon-note.c @@ -201,8 +201,8 @@ START_TEST (test_new_information_regular) g_object_get_property(G_OBJECT (note),"note_type",&enum_value); note_type = g_value_get_int(&enum_value); - fail_if( note_type != HILDON_NOTE_TYPE_INFORMATION_THEME, - "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_INFORMATION_THEME)",note_type); + fail_if( note_type != HILDON_NOTE_TYPE_INFORMATION, + "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_INFORMATION)",note_type); gtk_widget_destroy (GTK_WIDGET (note)); note=NULL; @@ -221,8 +221,8 @@ START_TEST (test_new_information_regular) g_object_get_property(G_OBJECT (note),"note_type",&enum_value); note_type = g_value_get_int(&enum_value); - fail_if( note_type != HILDON_NOTE_TYPE_INFORMATION_THEME, - "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_INFORMATION_THEME)",note_type); + fail_if( note_type != HILDON_NOTE_TYPE_INFORMATION, + "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_INFORMATION)",note_type); gtk_widget_destroy (GTK_WIDGET (note)); note=NULL; @@ -264,8 +264,8 @@ START_TEST (test_new_information_invalid) g_object_get_property(G_OBJECT (invalid_note),"note_type",&enum_value); note_type = g_value_get_int(&enum_value); - fail_if( note_type != HILDON_NOTE_TYPE_INFORMATION_THEME, - "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_INFORMATION_THEME)",note_type); + fail_if( note_type != HILDON_NOTE_TYPE_INFORMATION, + "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_INFORMATION)",note_type); gtk_widget_destroy (GTK_WIDGET (invalid_note)); invalid_note=NULL; @@ -280,149 +280,6 @@ START_TEST (test_new_information_invalid) } END_TEST -#ifndef HILDON_DISABLE_DEPRECATED -/* ----- Test case for new_confirmation_with_icon_name -----*/ -/** - * Purpose: Check that note dialog is properly created with description regular values. - * Cases considered: - * - Create new confirmation note with description set to TEST_STRING and icon name "control_calibration_target". - * - Create new confirmation note with description set to "" and icon name NULL. - * - */ -START_TEST (test_new_confirmation_with_icon_name_regular) -{ - const gchar * description = NULL; - const gchar * ret_description = NULL; - const gchar *icon_name = NULL; - const gchar * ret_icon_name = NULL; - GValue value={0, }; - GValue icon_name_value={0, }; - GValue enum_value={0, }; - HildonNoteType note_type; - - g_value_init (&value, G_TYPE_STRING); - g_value_init (&icon_name_value, G_TYPE_STRING); - g_value_init (&enum_value, G_TYPE_INT); - - /* Test 1: create new confirmation note with description set to TEST_STRING */ - description = TEST_STRING; - icon_name="control_calibration_target"; - note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(n_window,description,icon_name)); - fail_if(!HILDON_IS_NOTE(note), - "hildon-note: Creation failed with hildon_note_new_confirmation_with_icon_name"); - - g_object_get_property(G_OBJECT (note),"description",&value); - ret_description = g_value_get_string (&value); - fail_if( strcmp (description,ret_description) != 0, - "hildon-note: Description (%s) was not set properly on creation. Returned description: %s", - description,ret_description); - - g_object_get_property(G_OBJECT (note),"note_type",&enum_value); - note_type = g_value_get_int(&enum_value); - fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION, - "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type); - - g_object_get_property(G_OBJECT (note),"icon",&icon_name_value); - ret_icon_name = g_value_get_string (&icon_name_value); - fail_if( strcmp (icon_name,ret_icon_name) != 0, - "hildon-note: icon_name (%s) was not set properly on creation. Returned icon_name: %s", - icon_name,ret_icon_name); - - gtk_widget_destroy (GTK_WIDGET (note)); - note=NULL; - - /* Test 2: create new confirmation note with description set to "" and icon name set to NULL */ - description = ""; - icon_name=NULL; - note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(n_window,description,icon_name)); - fail_if(!HILDON_IS_NOTE(note), - "hildon-note: Creation failed with hildon_note_new_confirmation_with_icon_name"); - - g_object_get_property(G_OBJECT (note),"description",&value); - ret_description = g_value_get_string (&value); - fail_if( strcmp (description,ret_description) != 0, - "hildon-note: Description (%s) was not set properly on creation. Returned description: %s", - description,ret_description); - - g_object_get_property(G_OBJECT (note),"note_type",&enum_value); - note_type = g_value_get_int(&enum_value); - fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION, - "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type); - - g_object_get_property(G_OBJECT (note),"icon",&icon_name_value); - ret_icon_name = g_value_get_string (&icon_name_value); - fail_if( ret_icon_name != NULL, - "hildon-note: icon_name (%s) was not set properly on creation. Returned icon_name: %s", - icon_name,ret_icon_name); - - gtk_widget_destroy (GTK_WIDGET (note)); - note=NULL; - - g_value_unset(&value); - g_value_unset(&icon_name_value); - g_value_unset(&enum_value); - -} -END_TEST - -/** - * Purpose: Check that note dialog is properly created with description invalid values. - * Cases considered: - * - Create new confirmation note with window set to NULL. - * - Create new confirmation note with description set to "NULL". - * - */ -START_TEST (test_new_confirmation_with_icon_name_invalid) -{ - const gchar * ret_description = NULL; - const gchar * ret_icon_name = NULL; - GValue value={0, }; - GValue enum_value={0, }; - GValue icon_name_value={0, }; - HildonNoteType note_type; - HildonNote * invalid_note; - - g_value_init (&value, G_TYPE_STRING); - g_value_init (&icon_name_value, G_TYPE_STRING); - g_value_init (&enum_value, G_TYPE_INT); - - /* Test 1: create new confirmation note with window set to "NULL" */ - invalid_note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(NULL,"","")); - fail_if(!HILDON_IS_NOTE(invalid_note), - "hildon-note: Creation failed with hildon_note_new_confirmation_with_icon_name"); - - g_object_get_property(G_OBJECT (invalid_note),"description",&value); - ret_description = g_value_get_string (&value); - fail_if( strcmp ("",ret_description) != 0, - "hildon-note: Description "" was not set properly on creation. Returned description: %s", - ret_description); - - g_object_get_property(G_OBJECT (invalid_note),"icon",&icon_name_value); - ret_icon_name = g_value_get_string (&icon_name_value); - fail_if( strcmp ("",ret_icon_name) != 0, - "hildon-note: Description "" was not set properly on creation. Returned description: %s", - ret_icon_name); - - g_object_get_property(G_OBJECT (invalid_note),"note_type",&enum_value); - note_type = g_value_get_int(&enum_value); - fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION, - "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type); - - gtk_widget_destroy (GTK_WIDGET (invalid_note)); - invalid_note=NULL; - - /* Test 2: create new confirmation note with description set to "NULL" */ - invalid_note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(n_window,NULL,"control_calibration_target")); - fail_if(HILDON_IS_NOTE(invalid_note), - "hildon-note: Creation succeeded with hildon_note_new_confirmation_with_icon_name with message == NULL"); - - g_value_unset(&icon_name_value); - g_value_unset(&value); - g_value_unset(&enum_value); -} -END_TEST -#endif - /* ----- Test case for new_cancel_with_progress_bar -----*/ /** @@ -557,9 +414,6 @@ Suite *create_hildon_note_suite() /* Create test cases */ TCase *tc1 = tcase_create("new_confirmation"); -#ifndef HILDON_DISABLE_DEPRECATED - TCase *tc2 = tcase_create("new_confirmation_with_icon_name"); -#endif TCase *tc3 = tcase_create("new_information"); TCase *tc4 = tcase_create("new_cancel_with_progress_bar"); @@ -569,14 +423,6 @@ Suite *create_hildon_note_suite() tcase_add_test(tc1, test_new_confirmation_invalid); suite_add_tcase (s, tc1); -#ifndef HILDON_DISABLE_DEPRECATED - /* Create test case for hildon_note_new_confirmation_with_icon_name and add it to the suite */ - tcase_add_checked_fixture(tc2, fx_setup_default_note, fx_teardown_default_note); - tcase_add_test(tc2, test_new_confirmation_with_icon_name_regular); - tcase_add_test(tc2, test_new_confirmation_with_icon_name_invalid); - suite_add_tcase (s, tc2); -#endif - /* Create test case for hildon_note_new_with_information and add it to the suite */ tcase_add_checked_fixture(tc3, fx_setup_default_note, fx_teardown_default_note); tcase_add_test(tc3, test_new_information_regular); diff --git a/tests/check-hildon-number-editor.c b/tests/check-hildon-number-editor.c deleted file mode 100644 index 994574f..0000000 --- a/tests/check-hildon-number-editor.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <glib/gprintf.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-number-editor.h> - -/* -------------------- Fixtures -------------------- */ - -static HildonNumberEditor *number_editor = NULL; -static GtkWidget *showed_window = NULL; - -static void -fx_setup_default_number_editor () -{ - int argc = 0; - gtk_init(&argc, NULL); - - number_editor = HILDON_NUMBER_EDITOR(hildon_number_editor_new(0, 100)); - /* Check number_editor object has been created properly */ - fail_if(!HILDON_IS_NUMBER_EDITOR(number_editor), - "hildon-number-editor: Creation failed."); - - showed_window = create_test_window (); - - /* This packs the widget into the window (a gtk container). */ - gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (number_editor)); - - /* Displays the widget and the window */ - show_all_test_window (showed_window); -} - -static void -fx_teardown_default_number_editor () -{ - gtk_widget_destroy (GTK_WIDGET (number_editor)); -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_range -----*/ - -/** - * Purpose: Check that the ranges can be set safely - * Cases considered: - * - Set a number limit of (0, 100) - * - Set a number limit of (1, 100) - * - Set a number limit of (-100, 100) - * - Set a number limit of (-100, 0) - * - Set a number limit of (-100, -1) - */ -START_TEST (test_set_range_regular) -{ - gint number; - - /* Test 1: Set limits to (0, 100) */ - hildon_number_editor_set_range(number_editor, 0, 100); - - hildon_number_editor_set_value(number_editor, 0); - - hildon_number_editor_set_value(number_editor, 101); - number = hildon_number_editor_get_value(number_editor); - fail_if (number != 0, - "hildon-number-editor: range_value failed, we set range: 0/100, we set 0 and then we set the value 101 but we get %d instead of 0", - number); - - /* Test 2: Set limits to (1, 100) */ - hildon_number_editor_set_range(number_editor, 1, 100); - - hildon_number_editor_set_value(number_editor, 1); - - hildon_number_editor_set_value(number_editor, 0); - number = hildon_number_editor_get_value(number_editor); - fail_if (number != 1, - "hildon-number-editor: range_value failed, we set range: 0/100, we set 0 and then we set the value -1 but we get %d instead of 0", - number); - - /* Test 3: Set limits to (-100, 100) */ - hildon_number_editor_set_range(number_editor, -100, 100); - - hildon_number_editor_set_value(number_editor, 0); - - hildon_number_editor_set_value(number_editor, -101); - number = hildon_number_editor_get_value(number_editor); - fail_if (number != 0, - "hildon-number-editor: range_value failed, we set range: 0/100, we set 0 and then we set the value -101 but we get %d instead of 0", - number); - - /* Test 4: Set limits to (-100, 0) */ - hildon_number_editor_set_range(number_editor, -100, 0); - - hildon_number_editor_set_value(number_editor, 0); - - hildon_number_editor_set_value(number_editor, 1); - number = hildon_number_editor_get_value(number_editor); - fail_if (number != 0, - "hildon-number-editor: range_value failed, we set range: 0/100, we set 0 and then we set the value 1 but we get %d instead of 0", - number); - - /* Test 5: Set limits to (-100, -1) */ - hildon_number_editor_set_range(number_editor, -100, -1); - - hildon_number_editor_set_value(number_editor, -1); - - hildon_number_editor_set_value(number_editor, 0); - number = hildon_number_editor_get_value(number_editor); - fail_if (number != -1, - "hildon-number-editor: range_value failed, we set range: 0/100, we set -1 and then we set the value 0 but we get %d instead of -1", - number); -} -END_TEST - -/** - * Purpose: Check that the ranges limits are controlled properly - * Cases considered: - * - Set G_MAXINT and G_MININT - * - Set a number limit of (0, 100), and test that 0 and 100 work properly - */ -START_TEST (test_set_range_limits) -{ - gint number; - - /* Test 6: Set limits to (G_MININT, G_MAXINT) */ - hildon_number_editor_set_range(number_editor, G_MININT, G_MAXINT); - - /* Test 7: Set limits to (0,100) */ - hildon_number_editor_set_value(number_editor, 0); - - number = hildon_number_editor_get_value(number_editor); - fail_if (number != 0, - "hildon-number-editor: range_value failed, we set range: 0/100, we set 0 but we get %d instead of 0", - number); - - hildon_number_editor_set_value(number_editor, 100); - - number = hildon_number_editor_get_value(number_editor); - fail_if (number != 100, - "hildon-number-editor: range_value failed, we set range: 0/100, we set 100 but we get %d instead of 100", - number); -} -END_TEST - -/** - * Purpose: Check that the invalid values are controlled properly we - * use set/get value to test if our first value is modified - * - * Cases considered: - * - Change the order of the minimum and maximum and check if it does not change (200, -2) - * - Set values where high value is less than low value (0, 100) - * - Set a range to a NULL widget - */ -START_TEST (test_set_range_invalid) -{ - gint number; - - /* Test 8: Set limits to (200, -2) */ - hildon_number_editor_set_range(number_editor, 200, -2); - - hildon_number_editor_set_value(number_editor, 0); - - /* we set 101 and it should not be set if method didn't reverse min and max, the value may continue being 0 */ - hildon_number_editor_set_value(number_editor, 101); - number = hildon_number_editor_get_value(number_editor); - fail_if (number != 101, - "hildon-number-editor: range_value failed, we set range: 200/-2, and it should not be set so 0/100 should continue being the range, we set 0 and then we set the value 101 but we get %d instead of 0", - number); - - /* Test 9: Set limits to (100, 0) */ - hildon_number_editor_set_range(number_editor, 0, 100); - - hildon_number_editor_set_value(number_editor, 0); - - /* we set -5 and it should not be set, the value may continue being 0 */ - hildon_number_editor_set_value(number_editor, -5); - number = hildon_number_editor_get_value(number_editor); - fail_if (number != 0, - "hildon-number-editor: range_value failed, we set range: 0/100, we set 0 and then we set the value -5 but we get %d instead of 0", - number); - - /* we set 101 and it should not be set, the value may continue being 0 */ - hildon_number_editor_set_value(number_editor, 101); - number = hildon_number_editor_get_value(number_editor); - fail_if (number != 0, - "hildon-number-editor: range_value failed, we set range: 0/100, we set 0 and then we set the value 101 but we get %d instead of 0", - number); - - /* Test 10: Set a range to a NULL widget */ - hildon_number_editor_set_range(NULL, 0, 100); - -} -END_TEST - - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_number_editor_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonNumberEditor"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_number"); - - /* Create test case for set_number and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_number_editor, fx_teardown_default_number_editor); - tcase_add_test(tc1, test_set_range_regular); - tcase_add_test(tc1, test_set_range_limits); - tcase_add_test(tc1, test_set_range_invalid); - suite_add_tcase (s, tc1); - - /* Return created suite */ - return s; -} - - diff --git a/tests/check-hildon-range-editor.c b/tests/check-hildon-range-editor.c deleted file mode 100644 index cc1f214..0000000 --- a/tests/check-hildon-range-editor.c +++ /dev/null @@ -1,382 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-range-editor.h> -#include <unistd.h> - -/* -------------------- Fixtures -------------------- */ - -static GtkWidget *showed_window = NULL; -static HildonRangeEditor *range_editor = NULL; - -static void -fx_setup_default_range_editor () -{ - int argc = 0; - gtk_init(&argc, NULL); - - range_editor = HILDON_RANGE_EDITOR(hildon_range_editor_new()); - - showed_window = create_test_window (); - - /* This packs the widget into the window (a gtk container). */ - gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (range_editor)); - - /* Displays the widget and the window */ - show_all_test_window (showed_window); - - /* Check range_editor object has been created properly */ - fail_if(!HILDON_IS_RANGE_EDITOR(range_editor), - "hildon-range-editor: Creation failed."); - - - while (gtk_events_pending ()) - { - gtk_main_iteration (); - } - -} - -static void -fx_teardown_default_range_editor () -{ - - /* Destroy the window */ - gtk_widget_destroy (showed_window); -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_limit, get_min, get_max -----*/ - -/** - * Purpose: Check that regular range limit values are set and get properly - * Cases considered: - * - Set limits to (-10,10) and get min/max using the range editor object - * - Set limits to (0,10) and get min/max using the range editor object - * - Set limits to (-10,0) and get min/max using the range editor object - * - Set limits to (1,10) and get min/max using the range editor object - * - Set limits to (-10,-10) and get min/max using the range editor object - */ -START_TEST (test_set_limits_get_min_get_max_regular) -{ - gint range_start, range_end; - - /* Test1: Set limits to (-10,10) */ - hildon_range_editor_set_limits(range_editor, -10, 10); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != -10, - "hildon-range-editor: set limits to (-10,10) but get_min didn't return -10"); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != 10, - "hildon-range-editor: set limits to (-10,10) but get_max didn't return 10"); - - /* Test2: Set limits to (0,10) */ - hildon_range_editor_set_limits(range_editor, 0, 10); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != 0, - "hildon-range-editor: set limits to (0,10) but get_min didn't return 0"); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != 10, - "hildon-range-editor: set limits to (0,10) but get_max didn't return 10"); - - /* Test3: Set limits to (-10,0) */ - hildon_range_editor_set_limits(range_editor, -10, 0); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != -10, - "hildon-range-editor: set limits to (-10,0) but get_min didn't return -10"); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != 0, - "hildon-range-editor: set limits to (-10,0) but get_max didn't return 0"); - - /* Test4: Set limits to (1,10) */ - hildon_range_editor_set_limits(range_editor, 1, 10); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != 1, - "hildon-range-editor: set limits to (1,10) but get_min didn't return 1"); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != 10, - "hildon-range-editor: set limits to (1,10) but get_max didn't return 10"); - - /* Test5: Set limits to (-10,-1) */ - hildon_range_editor_set_limits(range_editor, -10, -1); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != -10, - "hildon-range-editor: set limits to (-10,-1) but get_min didn't return -10"); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != -1, - "hildon-range-editor: set limits to (-10,-1) but get_max didn't return -1"); -} -END_TEST - -/** - * Purpose: Check that range limit values are set and get properly - * Cases considered: - * - Set limits to (G_MININT,G_MAXINT) and get min/max using the range editor object - */ -START_TEST (test_set_limits_get_min_get_max_limits) -{ - gint range_start, range_end; - - /* Test1: Set limits to (G_MININT,G_MAXINT) */ - hildon_range_editor_set_limits(range_editor, G_MININT, G_MAXINT); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != G_MININT, - "hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_min didn't return G_MININT"); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != G_MAXINT, - "hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_max didn't return G_MAXINT"); -} -END_TEST - -/** - * Purpose: Check that invalid values are handled properly - * Cases considered: - * - Set inverted limits (10,-10) - * - Set range editor object to NULL for set_limits - * - Set range editor object to NULL for get_min and get_max - */ -START_TEST (test_set_limits_get_min_get_max_invalid) -{ - gint range_start, range_end; - - /* Test1: Set limits to (10,-10) */ - hildon_range_editor_set_limits(range_editor, 10, -10); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != -10, - "hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_min didn't return -10"); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != -10, - "hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_max didn't return -1"); - - /* Test2: set range editor to NULL for set_limits. */ - hildon_range_editor_set_limits(NULL, 100, -100); - - /* Test3: set range editor to NULL for get_min and get_max */ - range_start = hildon_range_editor_get_min(NULL); - fail_if(range_start != 0, - "hildon-range-editor: setting range editor to NULL produced get_min to return a value != 0"); - range_end = hildon_range_editor_get_max(NULL); - fail_if(range_end != 0, - "hildon-range-editor: setting range editor to NULL produced get_max to return a value != 0"); -} -END_TEST - - -/* ----- Test case for set_min -----*/ - -/** - * Purpose: Check regular minimum values for limits are set properly - * Cases considered: - * - Set min limit to -100 - * - Set min limit to 0 - * - Set min limit to 100 - */ -START_TEST (test_set_min_regular) -{ - gint range_start; - - /* Test1: Set min limits -100 */ - hildon_range_editor_set_min(range_editor, -100); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != -100, - "hildon-range-editor: set min limit to -100 but get_min didn't return -100"); - - /* Test2: Set min limits 0 */ - hildon_range_editor_set_min(range_editor, 0); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != 0, - "hildon-range-editor: set min limit to 0 but get_min didn't return 0"); - - /* Test3: Set min limits 100 */ - hildon_range_editor_set_min(range_editor, 100); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != 100, - "hildon-range-editor: set min limit to 100 but get_min didn't return 100"); -} -END_TEST - -/** - * Purpose: Check limit minimum values for limits are set properly - * Cases considered: - * - Set min limit to G_MININT - */ -START_TEST (test_set_min_limits) -{ - gint range_start; - - /* Test1: Set min limit to G_MININT */ - hildon_range_editor_set_min(range_editor, G_MININT); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != G_MININT, - "hildon-range-editor: set min limit to G_MININT but get_min didn't return G_MININT"); -} -END_TEST - -/** - * Purpose: Check that invalid values are handled properly - * Cases considered: - * - Set minimum limit greater than maximum limit - * - Set range editor object to NULL for set_min - */ -START_TEST (test_set_min_invalid) -{ - gint range_start, range_end; - - /* Test1: Set minimum limit greater than maximum limit */ - hildon_range_editor_set_limits(range_editor, -10, 10); - hildon_range_editor_set_min(range_editor, 15); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != 15, - "hildon-range-editor: set min limit to 15 when max limit is 10 expecting to set limits to (15,15) but get_min didn't return 15"); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != 15, - "hildon-range-editor: set min limit to 15 when max limit is 10 expecting to set limits to (15,15) but get_max didn't return 15"); - - /* Test2: set range editor to NULL */ - hildon_range_editor_set_min(NULL, 15); -} -END_TEST - - -/* ----- Test case for set_max -----*/ - -/** - * Purpose: Check regular maximum values for limits are set properly - * Cases considered: - * - Set max limit to -100 - * - Set max limit to 0 - * - Set max limit to 100 - */ -START_TEST (test_set_max_regular) -{ - gint range_end; - - /* Test1: Set max limits -100 */ - hildon_range_editor_set_max(range_editor, -100); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != -100, - "hildon-range-editor: set max limit to -100 but get_max didn't return -100"); - - /* Test2: Set max limits 0 */ - hildon_range_editor_set_max(range_editor, 0); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != 0, - "hildon-range-editor: set max limit to 0 but get_max didn't return 0"); - - /* Test3: Set max limits 100 */ - hildon_range_editor_set_max(range_editor, 100); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != 100, - "hildon-range-editor: set max limit to 100 but get_max didn't return 100"); -} -END_TEST - -/** - * Purpose: Check limit maximum values for limits are set properly - * Cases considered: - * - Set min limit to G_MAXINT - */ -START_TEST (test_set_max_limits) -{ - gint range_end; - - /* Test1: Set max limit to G_MAXINT */ - hildon_range_editor_set_max(range_editor, G_MAXINT); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != G_MAXINT, - "hildon-range-editor: set min limit to G_MAXINT but get_max didn't return G_MAXINT"); -} -END_TEST - -/** - * Purpose: Check that invalid values are handled properly - * Cases considered: - * - Set maximum limit lower than minimum limit - * - Set range editor object to NULL for set_max - */ -START_TEST (test_set_max_invalid) -{ - gint range_start, range_end; - - /* Test1: Set maximum limit lower than minimum limit */ - hildon_range_editor_set_limits(range_editor, -10, 10); - hildon_range_editor_set_max(range_editor, -15); - range_start = hildon_range_editor_get_min(range_editor); - fail_if(range_start != -15, - "hildon-range-editor: set max limit to -15 when min limit is -10 expecting to set limits to (-15,-15) but get_min didn't return -15"); - range_end = hildon_range_editor_get_max(range_editor); - fail_if(range_end != -15, - "hildon-range-editor: set min limit to -15 when min limit is -10 expecting to set limits to (-15,-15) but get_max didn't return -15"); - - /* Test2: set range editor to NULL */ - hildon_range_editor_set_max(NULL, 15); -} -END_TEST - - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_range_editor_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonRangeEditor"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_limits_get_min_get_max"); - TCase *tc2 = tcase_create("set_min"); - TCase *tc3 = tcase_create("set_max"); - - /* Create test case for set_limits, get_min and get_max and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_range_editor, fx_teardown_default_range_editor); - tcase_add_test(tc1, test_set_limits_get_min_get_max_regular); - tcase_add_test(tc1, test_set_limits_get_min_get_max_limits); - tcase_add_test(tc1, test_set_limits_get_min_get_max_invalid); - suite_add_tcase (s, tc1); - - /* Create test case for set_min */ - tcase_add_checked_fixture(tc2, fx_setup_default_range_editor, fx_teardown_default_range_editor); - tcase_add_test(tc2, test_set_min_regular); - tcase_add_test(tc2, test_set_min_limits); - tcase_add_test(tc2, test_set_min_invalid); - suite_add_tcase (s, tc2); - - /* Create test case for set_max */ - tcase_add_checked_fixture(tc3, fx_setup_default_range_editor, fx_teardown_default_range_editor); - tcase_add_test(tc3, test_set_max_regular); - tcase_add_test(tc3, test_set_max_limits); - tcase_add_test(tc3, test_set_max_invalid); - suite_add_tcase (s, tc3); - - /* Return created suite */ - return s; -} - - diff --git a/tests/check-hildon-seekbar.c b/tests/check-hildon-seekbar.c deleted file mode 100644 index bb53c98..0000000 --- a/tests/check-hildon-seekbar.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkcontainer.h> -#include <glib/gprintf.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-seekbar.h> - -/* -------------------- Fixtures -------------------- */ - -static GtkWidget *showed_window = NULL; -static HildonSeekbar *seekbar = NULL; - -static void -fx_setup_default_seekbar () -{ - int argc = 0; - gtk_init(&argc, NULL); - - seekbar = HILDON_SEEKBAR(hildon_seekbar_new()); - - showed_window = create_test_window (); - - /* This packs the widget into the window (a gtk container). */ - gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (seekbar)); - - /* Displays the widget and the window */ - show_all_test_window (showed_window); - - /* Check that the seekbar object has been created properly */ - fail_if(!HILDON_SEEKBAR(seekbar), - "hildon-seekbar: Creation failed."); -} - -static void -fx_teardown_default_seekbar () -{ - - /* Destroy the window */ - gtk_widget_destroy (showed_window); -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_time -----*/ - -/** - * Purpose: test setting regular time values for hildon_seekbar_set_time - * Cases considered: - * - Set and get 1000 seconds without setting new position and fraction. - * - Set and get 500 seconds setting without setting new position but new fraction should be set. - * - Set and get 500 seconds setting without setting new position but new fraction should be set. - */ -START_TEST (test_set_time_regular) -{ - gint ret_seconds; - gint seconds; - gint position; - gint fraction; - - /* Test 1: Set and get 1000 seconds without setting new position and fraction */ - seconds = 1000; - hildon_seekbar_set_total_time(seekbar,seconds); - ret_seconds=hildon_seekbar_get_total_time(seekbar); - - fail_if(ret_seconds != seconds, - "hildon-seekbar: set seekbar total time to %d but get_total_time returns %d", - seconds,ret_seconds); - - - /* Test 2: Set and get 500 seconds with a fraction set to 750 and position set to 750 (in order to test the correct update of - position and fraction. */ - seconds = 500; - position = 750; - fraction = 750; - - hildon_seekbar_set_fraction(seekbar,fraction); - fail_if(fraction != hildon_seekbar_get_fraction(seekbar), - "hildon-seekbar: set total time to %d but get_fraction returns %d ", - fraction,hildon_seekbar_get_fraction(seekbar)); - - hildon_seekbar_set_position(seekbar,position); - fail_if(position != hildon_seekbar_get_position(seekbar), - "hildon-seekbar: set total time to %d but get_position returns %d", - position,hildon_seekbar_get_position(seekbar)); - - hildon_seekbar_set_total_time(seekbar,seconds); - fail_if(seconds != hildon_seekbar_get_fraction(seekbar), - "hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d", - seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar)); - - fail_if(seconds != hildon_seekbar_get_position(seekbar), - "hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d", - seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar)); - - ret_seconds=hildon_seekbar_get_total_time(seekbar); - fail_if(ret_seconds != seconds, - "hildon-seekbar: set total time to %d but get_total_time returns %d ", - seconds,ret_seconds); - - /* Test 3: Set and get 500 seconds with a fraction set to 750 and position set to 250 (in order to test the correct update of - position and fraction. - */ - seconds = 1000; - hildon_seekbar_set_total_time(seekbar,seconds); - - seconds = 500; - position = 250; - fraction = 750; - - hildon_seekbar_set_fraction(seekbar,fraction); - fail_if(fraction != hildon_seekbar_get_fraction(seekbar), - "hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d ", - fraction,hildon_seekbar_get_fraction(seekbar)); - - hildon_seekbar_set_position(seekbar,position); - fail_if(position != hildon_seekbar_get_position(seekbar), - "hildon-seekbar: set seekbar position to %d but get_position returns %d", - position,hildon_seekbar_get_position(seekbar)); - - hildon_seekbar_set_total_time(seekbar,seconds); - fail_if(fraction != hildon_seekbar_get_fraction(seekbar), - "hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d being total time %d", - seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar)); - - ret_seconds=hildon_seekbar_get_total_time(seekbar); - fail_if(ret_seconds != seconds, - "hildon-seekbar: set total time to %d but get_total_time returns %d ", - seconds,ret_seconds); -} -END_TEST - -/** - * Purpose: test setting limit time values for hildon_seekbar_set_time - * Cases considered: - * - Set and get 0 seconds setting new position and fraction (previously set to 750). - * - Set and get G_MAXINT seconds without setting new position and fraction. - */ -START_TEST (test_set_time_limits) -{ - gint ret_seconds; - gint seconds; - gint position; - gint fraction; - - seconds = 1000; - hildon_seekbar_set_total_time(seekbar,seconds); - - position = 750; - fraction = 750; - - hildon_seekbar_set_fraction(seekbar,fraction); - hildon_seekbar_set_position(seekbar,position); - - /* Test 1: Set and get 1 seconds without setting new position and fraction (time was previously set to 1000)*/ - seconds = 1; - hildon_seekbar_set_total_time(seekbar,seconds); - ret_seconds=hildon_seekbar_get_total_time(seekbar); - - fail_if(ret_seconds != seconds, - "hildon-seekbar: set seekbar total time to %d should return %d but get_total_time returns %d", - seconds,ret_seconds); - - /* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/ - fail_if(seconds != hildon_seekbar_get_fraction(seekbar), - "hildon-seekbar: set time to %d but get_fraction returns %d ", - seconds,hildon_seekbar_get_fraction(seekbar)); - - /* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/ - fail_if(seconds != hildon_seekbar_get_position(seekbar), - "hildon-seekbar: set time to %d but get_position returns %d", - seconds,hildon_seekbar_get_position(seekbar)); - - /* Test 2: Set and get G_MAXINT seconds without setting new position and fraction */ - seconds = G_MAXINT; - hildon_seekbar_set_total_time(seekbar,seconds); - ret_seconds=hildon_seekbar_get_total_time(seekbar); - - fail_if(ret_seconds != seconds, - "hildon-seekbar: set seekbar total time to %d but get_total_time returns %d", - seconds,ret_seconds); - - -} -END_TEST - - -/** - * Purpose: test setting invalid time values for hildon_seekbar_set_time - * Cases considered: - * - Set and get seconds to a NULL object. - * - Set and get 0 seconds without setting new position and fraction. - * - Set and get -1 seconds without setting new position and fraction. - */ -START_TEST (test_set_time_invalid) -{ - gint init_seconds; - gint ret_seconds; - gint seconds; - - init_seconds = 1000; - /* Test 1: Set/get seconds on NULL object */ - hildon_seekbar_set_total_time(NULL,init_seconds); - ret_seconds=hildon_seekbar_get_total_time(NULL); - - /* Init seekbar to 1000 seconds*/ - hildon_seekbar_set_total_time(seekbar,init_seconds); - - - /* Test 2: Set and get 0 seconds */ - seconds = 0; - hildon_seekbar_set_total_time(seekbar,seconds); - ret_seconds=hildon_seekbar_get_total_time(seekbar); - - fail_if(ret_seconds != init_seconds, - "hildon-seekbar: set seekbar total time to %d, should set %d but get_total_time returns %d", - seconds,init_seconds,ret_seconds); - - /* Test 3: Set and get -1 seconds */ - seconds = -1; - hildon_seekbar_set_total_time(seekbar,seconds); - ret_seconds=hildon_seekbar_get_total_time(seekbar); - - fail_if(ret_seconds != init_seconds, - "hildon-seekbar: set seekbar total time to %d, should return %d but get_total_time returns %d", - seconds,init_seconds,ret_seconds); - -} -END_TEST - -/* ----- Test case for set_fraction -----*/ - -/** - * Purpose: test setting regular fraction values for hildon_seekbar_set_fraction - * Cases considered: - * - Set and get fraction to 500 with total time set to 1000. - * - Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500. - */ -START_TEST (test_set_fraction_regular) -{ - gint ret_seconds; - gint init_seconds; - gint seconds; - - /* Init seekbar to 1000 */ - init_seconds = 1000; - hildon_seekbar_set_total_time(seekbar,init_seconds); - - /* Test 1: Set and get fraction to 500 with total time set to 1000 */ - seconds = 500; - hildon_seekbar_set_fraction(seekbar,seconds); - ret_seconds=hildon_seekbar_get_fraction(seekbar); - - fail_if(ret_seconds != seconds, - "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d", - seconds,ret_seconds); - - /* Test 2: Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500 */ - seconds = 500; - - hildon_seekbar_set_fraction(seekbar,seconds); - hildon_seekbar_set_position(seekbar,seconds); - - hildon_seekbar_set_fraction(seekbar,seconds-10); - - ret_seconds=hildon_seekbar_get_fraction(seekbar); - - fail_if(ret_seconds != seconds-10, - "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d", - seconds,ret_seconds); - - fail_if(hildon_seekbar_get_position(seekbar) != seconds-10, - "hildon-seekbar: set seekbar fraction to %d but get seekbar position returns %d", - seconds-10,hildon_seekbar_get_position(seekbar)); - -} -END_TEST - -/** - * Purpose: test setting limit fraction values for hildon_seekbar_set_fraction - * Cases considered: - * - Set and get fraction to 0 with total time set to G_MAXINT. - * - Set and get fraction to 1 with total time set to G_MAXINT. - * - Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT. - * - Set and get fraction to G_MAXINT with total time set to G_MAXINT. - */ -START_TEST (test_set_fraction_limits) -{ - gint ret_seconds; - gint seconds; - gint init_seconds; - - /* Init seekbar to G_MAXINT total time */ - init_seconds = G_MAXINT; - hildon_seekbar_set_total_time(seekbar,init_seconds); - - /* Test 1: Set and get fraction to 0 with total time set to G_MAXINT */ - seconds = 0; - hildon_seekbar_set_fraction(seekbar,seconds); - ret_seconds=hildon_seekbar_get_fraction(seekbar); - - fail_if(ret_seconds != seconds, - "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d", - seconds,ret_seconds); - - /* Test 2: Set and get fraction to 1 with total time set to G_MAXINT */ - seconds = 1; - hildon_seekbar_set_fraction(seekbar,seconds); - ret_seconds=hildon_seekbar_get_fraction(seekbar); - - fail_if(ret_seconds != seconds, - "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d", - seconds,ret_seconds); - - /* Test 3: Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT */ - seconds = G_MAXINT-1; - hildon_seekbar_set_fraction(seekbar,seconds); - ret_seconds=hildon_seekbar_get_fraction(seekbar); - - fail_if(ret_seconds != seconds, - "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d", - seconds,ret_seconds); - - /* Test 4: Set and get fraction to G_MAXINT with total time set to G_MAXINT */ - seconds = G_MAXINT; - - hildon_seekbar_set_fraction(seekbar,seconds); - ret_seconds=hildon_seekbar_get_fraction(seekbar); - - fail_if(ret_seconds != seconds, - "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d", - seconds,ret_seconds); - - -} -END_TEST - -/** - * Purpose: test setting invalid fraction values for hildon_seekbar_set_fraction - * Cases considered: - * - Set and get fraction to NULL object. - * - Set and get fraction to -1 with total time set to G_MAXINT. - * - Set and get fraction to 2000 with total time set to 1000. - */ -START_TEST (test_set_fraction_invalid) -{ - gint ret_seconds; - gint seconds; - gint init_seconds; - - /* Init seekbar to G_MAXINT total time */ - init_seconds = G_MAXINT; - hildon_seekbar_set_total_time(seekbar,init_seconds); - - /* Test 1: Set and get fraction to NULL object */ - seconds = 1000; - hildon_seekbar_set_fraction(NULL,seconds); - ret_seconds=hildon_seekbar_get_fraction(NULL); - - /* Test 2: Set and get fraction to -1 with total time set to G_MAXINT */ - seconds = -1; - hildon_seekbar_set_fraction(seekbar,seconds); - ret_seconds=hildon_seekbar_get_fraction(seekbar); - - fail_if(ret_seconds != 0, - "hildon-seekbar: set seekbar fraction to %d should set 0 but get seekbar fraction returns %d", - seconds,ret_seconds); - - /* Init seekbar to 1000 total time */ - init_seconds = 1000; - hildon_seekbar_set_total_time(seekbar,init_seconds); - hildon_seekbar_set_fraction(seekbar,init_seconds-500); - - /* Test 3: Set and get fraction to 2000 with total time set to 1000 */ - seconds = 2000; - hildon_seekbar_set_fraction(seekbar,seconds); - ret_seconds=hildon_seekbar_get_fraction(seekbar); - - fail_if(ret_seconds != init_seconds-500, - "hildon-seekbar: set seekbar fraction to %d should set %d but get seekbar fraction returns %d", - seconds,init_seconds,ret_seconds); - -} -END_TEST - - - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_seekbar_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonSeekbar"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_time"); - TCase *tc2 = tcase_create("set_fraction"); - - /* Create test case for hildon_seekbar_set_time and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_seekbar, fx_teardown_default_seekbar); - tcase_add_test(tc1, test_set_time_regular); - tcase_add_test(tc1, test_set_time_limits); - tcase_add_test(tc1, test_set_time_invalid); - suite_add_tcase (s, tc1); - - /* Create test case for hildon_seekbar_set_fraction and add it to the suite */ - tcase_add_checked_fixture(tc2, fx_setup_default_seekbar, fx_teardown_default_seekbar); - tcase_add_test(tc2, test_set_fraction_regular); - tcase_add_test(tc2, test_set_fraction_limits); - tcase_add_test(tc2, test_set_fraction_invalid); - suite_add_tcase (s, tc2); - - /* Return created suite */ - return s; -} - diff --git a/tests/check-hildon-set-password-dialog.c b/tests/check-hildon-set-password-dialog.c deleted file mode 100644 index 73ca67d..0000000 --- a/tests/check-hildon-set-password-dialog.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <string.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-set-password-dialog.h> -#include <hildon/hildon-window.h> - -/* -------------------- Fixtures -------------------- */ - -static HildonSetPasswordDialog *set_password_dialog = NULL; -static GtkWindow *spd_window=NULL; - -static void -fx_setup_default_set_password_dialog () -{ - int argc = 0; - - gtk_init(&argc, NULL); - spd_window = GTK_WINDOW(create_test_window()); - - /* Check window object has been created properly */ - fail_if(!HILDON_IS_WINDOW(spd_window), - "hildon-set_password_dialog: Window creation failed."); - - set_password_dialog = HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new(spd_window, TRUE)); - - /* Check that the set password dialog object has been created properly */ - fail_if(!HILDON_SET_PASSWORD_DIALOG(set_password_dialog), - "hildon-set_password_dialog: Creation failed."); - - show_test_window(GTK_WIDGET(spd_window)); - - show_test_window(GTK_WIDGET(set_password_dialog)); - -} - -static void -fx_teardown_default_set_password_dialog () -{ - - gtk_widget_destroy (GTK_WIDGET (set_password_dialog)); - - gtk_widget_destroy (GTK_WIDGET (spd_window)); - -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for get_protected -----*/ - -/** - * Purpose: Check that regular values are get properly. - * Cases considered: - * - Get TRUE from modify_protection property. - * - Get FALSE from modify_protection property. - * - */ -START_TEST (test_get_protected_regular) -{ - gboolean ret_protected; - HildonSetPasswordDialog *protected_test_password_dialog = NULL; - - /* I must create one dialog for each value of protected boolean because is a G_PARAM_CONSTRUCT_ONLY property */ - protected_test_password_dialog = HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new(spd_window, TRUE)); - - /* Test 1: Get TRUE from modify_protection property. */ - ret_protected = hildon_set_password_dialog_get_protected(set_password_dialog); - fail_if(ret_protected!=TRUE, - "hildon-set_password_dialog: modify_protection must be TRUE, but hildon_set_password_dialog_get_protected returns FALSE"); - - gtk_widget_destroy (GTK_WIDGET (protected_test_password_dialog)); - - /* Test 2: Get FALSE from modify_protection property */ - /* I must create one dialog for each value of protected boolean because is a G_PARAM_CONSTRUCT_ONLY property */ - protected_test_password_dialog = HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new(spd_window, FALSE)); - - ret_protected = hildon_set_password_dialog_get_protected(protected_test_password_dialog); - fail_if(ret_protected!=FALSE, - "hildon-set_password_dialog: modify_protection must be FALSE, but hildon_set_password_dialog_get_protected returns TRUE"); - - gtk_widget_destroy (GTK_WIDGET (protected_test_password_dialog)); -} -END_TEST - -/** - * Purpose: Check that invalid values are get properly. - * Cases considered: - * - Get modify_protection from NULL object. - * - */ -START_TEST (test_get_protected_invalid) -{ - gboolean ret_protected; - - ret_protected = hildon_set_password_dialog_get_protected (NULL); - fail_if (ret_protected != FALSE, - "hildon-set_password_dialog: modify_protection must be FALSE, but hildon_set_password_dialog_get_protected return TRUE"); -} -END_TEST - -/* ----- Test case for get_password -----*/ - -/** - * Purpose: Check that regular values are get properly. - * Cases considered: - * - Get password "test_password" from HildonSetPasswordDialog created with "test_password" by default. - * - Get password "" from HildonSetPasswordDialog created with "" by default. - * - Get password TEST_STRING from HildonSetPasswordDialog created with TEST_STRING by default. - */ -START_TEST (test_get_password_regular) -{ - const gchar * default_password=NULL; - const gchar * ret_password; - HildonSetPasswordDialog * default_set_password_dialog; - - - /* Test 1: Get password "test_password" from HildonSetPasswordDialog created with "test_password" by default. */ - default_password = "test_password"; - default_set_password_dialog = - HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new_with_default(spd_window,default_password,FALSE)); - fail_if(!HILDON_IS_SET_PASSWORD_DIALOG(default_set_password_dialog), - "hildon-set_password_dialog: hildon-set-password-dialog: Creation failed with hildon_set_password_dialog_new_with_default"); - - ret_password = hildon_set_password_dialog_get_password(default_set_password_dialog); - fail_if(strcmp (default_password,ret_password)!=0, - "hildon-set_password_dialog: default password and returned password are diferent (%s,%s)",default_password,ret_password); - - gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog)); - - /* Test 2: Create new dialog with password "" by default */ - default_password = ""; - default_set_password_dialog = - HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new_with_default(spd_window,default_password,FALSE)); - fail_if(!HILDON_IS_SET_PASSWORD_DIALOG(default_set_password_dialog), - "hildon-set-password-dialog: Creation failed with hildon_set_password_dialog_new_with_default"); - - ret_password = hildon_set_password_dialog_get_password(default_set_password_dialog); - fail_if(strcmp (default_password,ret_password)!=0, - "hildon-set_password_dialog: default password and returned password are diferent (%s,%s)",default_password,ret_password); - - gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog)); - - /* Test 3: Create new dialog with password TEST_STRING by default */ - default_password = TEST_STRING; - default_set_password_dialog = - HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new_with_default(spd_window,default_password,FALSE)); - fail_if(!HILDON_IS_SET_PASSWORD_DIALOG(default_set_password_dialog), - "hildon-set-password-dialog: Creation failed with hildon_set_password_dialog_new_with_default"); - - ret_password = hildon_set_password_dialog_get_password(default_set_password_dialog); - fail_if(strcmp (default_password,ret_password)!=0, - "hildon-set_password_dialog: default password and returned password are diferent (%s,%s)",default_password,ret_password); - - gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog)); - -} -END_TEST - -/** - * Purpose: Check that regular values are get properly. - * Cases considered: - * - Get empty password from HildonSetPasswordDialog created with NULL password by default. - * - Get password from NULL object. - */ -START_TEST (test_get_password_invalid) -{ - const gchar * ret_password; - HildonSetPasswordDialog * default_set_password_dialog; - - - /* Test 1: Get empty password from HildonSetPasswordDialog created with NULL password by default */ - default_set_password_dialog = - HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new_with_default(spd_window,NULL,FALSE)); - fail_if(!HILDON_IS_SET_PASSWORD_DIALOG(default_set_password_dialog), - "hildon-set-password-dialog: Creation failed with hildon_set_password_dialog_new_with_default"); - - ret_password = hildon_set_password_dialog_get_password(default_set_password_dialog); - fail_if(strcmp(ret_password,"")!=0, - "hildon-set_password_dialog: returned password is not empty"); - - gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog)); - - /* Test 2: Get password from NULL object */ - ret_password = hildon_set_password_dialog_get_password(NULL); - - fail_if(ret_password!=NULL, - "hildon-set_password_dialog: returned password is not null"); - -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_set_password_dialog_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonSetPasswordDialog"); - - /* Create test cases */ - TCase *tc1 = tcase_create("get_protected"); - TCase *tc2 = tcase_create("get_password"); - - /* Create test case for hildon_set_password_dialog_get_protected and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_set_password_dialog, fx_teardown_default_set_password_dialog); - tcase_add_test(tc1, test_get_protected_regular); - tcase_add_test(tc1, test_get_protected_invalid); - suite_add_tcase (s, tc1); - - /* Create test case for hildon_set_password_dialog_get_password and add it to the suite */ - tcase_add_checked_fixture(tc2, fx_setup_default_set_password_dialog, fx_teardown_default_set_password_dialog); - tcase_add_test(tc2, test_get_password_regular); - tcase_add_test(tc2, test_get_password_invalid); - suite_add_tcase (s, tc2); - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-sort-dialog.c b/tests/check-hildon-sort-dialog.c deleted file mode 100644 index 06a5fb7..0000000 --- a/tests/check-hildon-sort-dialog.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-sort-dialog.h> - -#define SORT_KEY_0 "maemo" -#define SORT_KEY_1 TEST_STRING -#define SORT_KEY_2 "" - -/* -------------------- Fixtures -------------------- */ - -static HildonSortDialog *sort_dialog = NULL; -static GtkWindow * showed_window = NULL; - -static void -fx_setup_default_sort_dialog () -{ - int argc = 0; - gtk_init(&argc, NULL); - - showed_window = GTK_WINDOW(create_test_window()); - - sort_dialog = HILDON_SORT_DIALOG(hildon_sort_dialog_new(showed_window)); - - show_test_window(GTK_WIDGET(showed_window)); - - show_test_window(GTK_WIDGET(sort_dialog)); - - /* Check sort_dialog object has been created properly */ - fail_if(!HILDON_IS_SORT_DIALOG(sort_dialog), - "hildon-sort-dialog: Creation failed."); -} - -static void -fx_teardown_default_sort_dialog () -{ - - gtk_widget_destroy (GTK_WIDGET (sort_dialog)); - - gtk_widget_destroy (GTK_WIDGET(showed_window)); - -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set/get_sort_key -----*/ - -/** - * Purpose: Test add, set and get of sort keys. - * Cases considered: - * - Add 3 keys to the list, then set and get key 1 - * - Unselect sort key - */ -START_TEST (test_add_set_get_sort_key_regular) -{ - gint ret_key; - - /* Test1: add 3 keys, then try to set and get key 1 */ - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_0); - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_1); - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_2); - - hildon_sort_dialog_set_sort_key(sort_dialog, 1); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key != 1, - "hildon-sort-dialog: Added keys \"%s\", \"%s\" and \"%s\", then set sort key 1, but get_sort_key returned value %d instead of 1", - SORT_KEY_0, SORT_KEY_1, SORT_KEY_2, ret_key); - - /* Test2: Unselect sort key */ - hildon_sort_dialog_set_sort_key(sort_dialog, -1); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key != -1, - "hildon-sort-dialog: Set sort key to -1, but get_sort_key returned value %d instead of -1", - ret_key); - -} -END_TEST - -/** - * Purpose: - * Cases considered: - * - Get of current key after dialog construction (empty list of keys) - * - Add 3 keys to the list, then set and get keys 0 and 2 - */ -START_TEST (test_add_set_get_sort_key_limits) -{ - gint ret_key; - - /* Test1: Get current key after construction */ - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key != -1, - "hildon-sort-dialog: After dialog construction current sort key index is %d instead of -1", - ret_key); - - /* Test2: Add 3 keys, then set and get keys 0 and 2 */ - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_0); - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_1); - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_2); - - hildon_sort_dialog_set_sort_key(sort_dialog, 0); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key != 0, - "hildon-sort-dialog: Added keys \"%s\", \"%s\" and \"%s\", then set sort key 0, but get_sort_key returned value %d instead of 0", - SORT_KEY_0, SORT_KEY_1, SORT_KEY_2, ret_key); - - hildon_sort_dialog_set_sort_key(sort_dialog, 2); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key != 2, - "hildon-sort-dialog: Added keys \"%s\", \"%s\" and \"%s\", then set sort key 2, but get_sort_key returned value %d instead of 2", - SORT_KEY_0, SORT_KEY_1, SORT_KEY_2, ret_key); -} -END_TEST - -/** - * Purpose: Check handling of invalid values regarding the sort keys management - * Cases considered: - * - Set of key with empty key list - * - Set negative key, lower than -1 - * - Set of key outside the range of a non empty key list - * - Set a duplicated key and check it is filtered - * - Add NULL sort key. - * - Add key with NULL object - * - Set key with NULL object - * - Get key with NULL object - */ -START_TEST (test_add_set_get_sort_key_invalid) -{ - gint ret_key; - - /* Test1: Set of a key with an empty key list */ - hildon_sort_dialog_set_sort_key(sort_dialog, 5); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key != -1, - "hildon-sort-dialog: Set sort key to 5 when the list of keys is empty, then retrieved current sort key and result was %d instead of -1", - ret_key); - - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_0); - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_1); - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_2); - - /* Test2: Set negative key lower than -1 */ - hildon_sort_dialog_set_sort_key(sort_dialog, 1); - hildon_sort_dialog_set_sort_key(sort_dialog, -3); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key != 1, - "hildon-sort-dialog: Set sort key to 1 when list of keys has 3 elements, then set sort key again to an invalid value of -3, then retrieved current sort key and result was %d instead of 1", - ret_key); - - /* Test3: Set of a positive key outside the range of a non empty key list */ - hildon_sort_dialog_set_sort_key(sort_dialog, 8); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key != -1, - "hildon-sort-dialog: Set sort key to 8 when the list of keys has 3 elements, then retrieved current sort key and result was %d instead of -1", - ret_key); - - /* This test breaks, because after setting an invalid positive value, get_sort_key returns -1 instead of - the last valid value set. I considered this an error because it does not the same when the invalid index is - negative (in that case it preserves the last valid index set) */ - hildon_sort_dialog_set_sort_key(sort_dialog, 1); - hildon_sort_dialog_set_sort_key(sort_dialog, 8); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - /* fail_if(ret_key != 1, - "hildon-sort-dialog: Set sort key to 1 when the list of keys has 3 elements, then set sort key again to an invalid index value of 8, then retrieved current sort key and result was %d instead of 1", - ret_key); - */ - fail_if(ret_key != -1, - "hildon-sort-dialog: Set sort key to 1 when the list of keys has 3 elements, then set sort key again to an invalid index value of 8, then retrieved current sort key and result was %d instead of 1", - ret_key); - - /* Test4: Add duplicated key */ - hildon_sort_dialog_add_sort_key(sort_dialog, SORT_KEY_0); - hildon_sort_dialog_set_sort_key(sort_dialog, 3); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key != 3, - "hildon-sort-dialog: Addition of duplicated sort keys is allowed."); - - /* Test5: Add NULL key */ - hildon_sort_dialog_add_sort_key(sort_dialog, NULL); - hildon_sort_dialog_set_sort_key(sort_dialog, 4); - ret_key = hildon_sort_dialog_get_sort_key(sort_dialog); - fail_if(ret_key == 4, - "hildon-sort-dialog: Addition of NULL sort key is allowed."); - - /* Test6: add key to a NULL object */ - hildon_sort_dialog_add_sort_key(NULL, SORT_KEY_0); - - /* Test7: set key in a NULL object */ - hildon_sort_dialog_set_sort_key(NULL, 0); - - /* Test8: get key in a NULL object */ - hildon_sort_dialog_get_sort_key(NULL); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_sort_dialog_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonSortDialog"); - - /* Create test cases */ - TCase *tc1 = tcase_create("add_get_set_sort_key"); - - /* Create test case for adding, getting and setting a sort key and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_sort_dialog, fx_teardown_default_sort_dialog); - tcase_add_test(tc1, test_add_set_get_sort_key_regular); - tcase_add_test(tc1, test_add_set_get_sort_key_limits); - tcase_add_test(tc1, test_add_set_get_sort_key_invalid); - suite_add_tcase (s, tc1); - - /* Return created suite */ - return s; -} - - diff --git a/tests/check-hildon-time-editor.c b/tests/check-hildon-time-editor.c deleted file mode 100644 index 26a6a7a..0000000 --- a/tests/check-hildon-time-editor.c +++ /dev/null @@ -1,1423 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtkcontainer.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <unistd.h> - -#include <hildon/hildon-time-editor.h> - -#define MIN_DURATION 0 -#define MAX_DURATION 359999 - -/* -------------------- Fixtures -------------------- */ - -static GtkWidget *showed_window = NULL; -/* static HildonTimeEditor *time_editor = NULL; */ - -static void -fx_setup_default_time_editor () -{ - int argc = 0; - - gtk_init(&argc, NULL); - - showed_window = create_test_window (); -} - -static void -fx_teardown_default_time_editor () -{ - /* Destroy the window */ - gtk_widget_destroy (showed_window); -} - -static HildonTimeEditor *create_and_show_time_editor(GtkWidget *window, gboolean seconds,gboolean duration) -{ - HildonTimeEditor *time_editor = NULL; - - time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new()); - - hildon_time_editor_set_show_seconds(time_editor,seconds); - hildon_time_editor_set_duration_mode(time_editor,duration); - - /* Add some widgets to the window and displays the window */ - gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(time_editor)); - show_all_test_window (window); - - hildon_time_editor_set_duration_mode(time_editor,duration); - - fail_if( !HILDON_IS_TIME_EDITOR(time_editor),"hildon-time-editor: Creation failed."); - return time_editor; -} - -static void remove_and_destroy_time_editor(GtkWidget *window,HildonTimeEditor ** time_editor) -{ - - gtk_container_remove (GTK_CONTAINER (window), GTK_WIDGET(*time_editor)); - gtk_widget_hide_all (window); - -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_time -----*/ - -/** - * Purpose: Check that regular time values are set and get properly - * Cases considered: - * - Set and get time to 5h 30m using time editor object. - * - Set and get time to 18h 2m using time editor object. - * - Set and get time to 5h 30m 45s using time editor object. - * - Set and get time to 18h 2m 5s using time editor object. - * - Set and get time to 5:30:45 using time editor object with duration mode. - * - Set and get time to 50:40:30 using time editor object with duration mode. - */ -START_TEST (test_set_time_regular) -{ - guint initial_hours; - guint initial_minutes; - guint initial_seconds; - guint hours; - guint minutes; - guint seconds; - HildonTimeEditor *time_editor = NULL; - - /* Test 1: Set time value to 5h 30m 0s to test time (am) without seconds */ - initial_hours=5; - initial_minutes=30; - initial_seconds=0; - - time_editor = create_and_show_time_editor(showed_window,FALSE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm). Result values are: (%dh %dm)", - initial_hours,initial_minutes,hours,minutes); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 2: Set time value to 18h 2m 0s to test time (pm) without seconds*/ - initial_hours=18; - initial_minutes=2; - initial_seconds=0; - - time_editor = create_and_show_time_editor(showed_window,FALSE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm). Result values are: (%dh %dm)", - initial_hours,initial_minutes,hours,minutes); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 3: Set time value to 5h 30m 45s to test time (am) with seconds*/ - initial_hours=5; - initial_minutes=30; - initial_seconds=45; - - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm %ds). Result values are: (%dh %dm %ds)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 4: Set time value to 18h 2m 5s to test time (pm) with seconds */ - initial_hours=18; - initial_minutes=2; - initial_seconds=5; - - - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm %ds). Result values are: (%dh %dm %ds)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 5: Set time value to 5:30:45 to test duration*/ - initial_hours=5; - initial_minutes=30; - initial_seconds=45; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%d:%d:%d). Result values are: (%d:%d:%d)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 6: Set time value to 50:40:30 to test duration */ - initial_hours=50; - initial_minutes=40; - initial_seconds=30; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%d:%d:%d). Result values are: (%d:%d:%d)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - -} -END_TEST - -/** - * Purpose: Check that limit time values are set and get properly - * Cases considered: - * - Set and get time to 0h 0m using time editor object. - * - Set and get time to 23h 59m using time editor object. - * - Set and get time to 23h 59m 59s using time editor object. - * - Set and get time to 0h 59m 59s using time editor object. - * - Set and get time to 99:59:59 using time editor object on duration mode. - * - Set and get time to 0:0:0 using time editor object on duration mode. - */ -START_TEST (test_set_time_limits) -{ - guint initial_hours; - guint initial_minutes; - guint initial_seconds; - guint hours; - guint minutes; - guint seconds; - HildonTimeEditor *time_editor = NULL; - - /* Test 1: Set time value to 00h 00m 00s to test time (am) without seconds*/ - initial_hours=0; - initial_minutes=0; - initial_seconds=0; - - time_editor = create_and_show_time_editor(showed_window,FALSE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm). Result values are: (%dh %dm)", - initial_hours,initial_minutes,hours,minutes); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 2: Set time value to 23h 59m 0s to test time (pm) without seconds*/ - initial_hours=23; - initial_minutes=59; - initial_seconds=0; - - time_editor = create_and_show_time_editor(showed_window,FALSE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm). Result values are: (%dh %dm)", - initial_hours,initial_minutes,hours,minutes); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 3: Set time value to 23h 59m 59s to test time (am) with seconds*/ - initial_hours=23; - initial_minutes=59; - initial_seconds=59; - - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm %ds). Result values are: (%dh %dm %ds)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 4: Set time value to 0h 59m 59s to test time (am) with seconds */ - initial_hours=0; - initial_minutes=59; - initial_seconds=59; - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm %ds). Result values are: (%dh %dm %ds)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 5: Set time value to 99:59:59 to test with duration mode */ - initial_hours=99; - initial_minutes=59; - initial_seconds=59; - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm %ds). Result values are: (%dh %dm %ds)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 6: Set time value to 0:0:0 to test with duration mode */ - initial_hours=0; - initial_minutes=0; - initial_seconds=0; - - time_editor = create_and_show_time_editor(showed_window,FALSE,TRUE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((hours != initial_hours) || (minutes != initial_minutes) || (seconds != initial_seconds), - "hildon-time-editor: set_time or get_time failed with values (%dh %dm %ds). Result values are: (%dh %dm %ds)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - -} -END_TEST - -/** - * Purpose: Check that invalid time values are set and get properly - * Cases considered: - * - Set NULL the editor time object. - * - Test NULL (time object) on get_time - * - Set and get time to 0h 60m using time editor object. - * - Set and get time to 0h 0m 60s using time editor object. - * - Set and get time to 24h 60m 60s using time editor object. - * - Set and get time to 50h 100m 100s using time editor object. - * - Set and get time to 0:80:80 using time editor object. - * - Set and get time to 110:80:80 using time editor object. - */ -START_TEST (test_set_time_invalid) -{ - guint initial_hours; - guint initial_minutes; - guint initial_seconds; - guint expected_hours; - guint expected_minutes; - guint expected_seconds; - guint hours; - guint minutes; - guint seconds; - HildonTimeEditor *time_editor = NULL; - - /* Initialization to test 1, test 2 and test 3*/ - initial_hours=0; - initial_minutes=60; - initial_seconds=0; - expected_hours=1; - expected_minutes=0; - expected_seconds=0; - - /* Test 1: Set NULL (set_time) */ - hildon_time_editor_set_time (NULL,initial_hours,initial_minutes,initial_seconds); - - /* Test 2: Set NULL (get_time) */ - hildon_time_editor_get_time(NULL,&hours,&minutes,&seconds); - - /* Test 3: Set time value to 00h 60m 00s to test time (am) without seconds and expect the correct value 01h 00m 00s */ - - time_editor = create_and_show_time_editor(showed_window,FALSE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - fail_if((expected_hours != hours) || (expected_minutes != minutes) || (expected_seconds != seconds), - "hildon-time-editor: set_time/get_time failed with (%dh %dm). Result values are (%dh %dm) and expected values are (%dh %dm)", - initial_hours,initial_minutes,hours,minutes,expected_hours,expected_minutes); - - /* Test 4: Set time value to 0h 0m 60s to test time (pm) without seconds and expect the correct value 00h 01m 00s*/ - initial_hours=0; - initial_minutes=0; - initial_seconds=60; - expected_hours=0; - expected_minutes=1; - expected_seconds=0; - - time_editor = create_and_show_time_editor(showed_window,FALSE,TRUE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((expected_hours != hours) || (expected_minutes != minutes) || (expected_seconds != seconds), - "hildon-time-editor: set_time/get_time failed with (%dh %dm %ds). Result values are (%dh %dm %ds) and expected values are (%dh %dm %ds)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds,expected_hours,expected_minutes,expected_seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 5: Set time value to 24h 60m 60s to test time (am) with seconds*/ - initial_hours=24; - initial_minutes=60; - initial_seconds=60; - expected_hours=23; - expected_minutes=1; - expected_seconds=0; - - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((expected_hours != hours) || (expected_minutes != minutes) || (expected_seconds != seconds), - "hildon-time-editor: set_time/get_time failed with values (%dh %dm %ds). Result values are (%dh %dm %ds) and expected values are (%dh %dm %ds)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds,expected_hours,expected_minutes,expected_seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 6: Set time value to 50h 100m 100s to test time (am) with seconds */ - initial_hours=50; - initial_minutes=100; - initial_seconds=100; - expected_hours=23; - expected_minutes=41; - expected_seconds=40; - - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((expected_hours != hours) || (expected_minutes != minutes) || (expected_seconds != seconds), - "hildon-time-editor: set_time/get_time failed with values (%d:%dm:%ds). Result values are (%d:%dm:%ds) and expected values are (%d:%dm:%ds)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds,expected_hours,expected_minutes,expected_seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 7: Set time value to 0:80:80 to test with duration mode */ - initial_hours=0; - initial_minutes=80; - initial_seconds=80; - expected_hours=1; - expected_minutes=21; - expected_seconds=20; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - fail_if((expected_hours != hours) || (expected_minutes != minutes) || (expected_seconds != seconds), - "hildon-time-editor: set_time/get_time failed with values (%d:%d:%d). Result values are (%d:%d:%d) and expected values are (%d:%d:%d)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds,expected_hours,expected_minutes,expected_seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 8: Set time value to 110:80:80 to test with duration mode */ - initial_hours=110; - initial_minutes=80; - initial_seconds=80; - expected_hours=99; - expected_minutes=59; - expected_seconds=59; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_time(time_editor,initial_hours,initial_minutes,initial_seconds); - - hildon_time_editor_get_time(time_editor,&hours,&minutes,&seconds); - - - fail_if((expected_hours != hours) || (expected_minutes != minutes) || (expected_seconds != seconds), - "hildon-time-editor: set_time/get_time failed with values (%d:%d:%d). Result values are (%d:%d:%d) and expected values are (%d:%d:%d)", - initial_hours,initial_minutes,initial_seconds,hours,minutes,seconds,expected_hours,expected_minutes,expected_seconds); - - remove_and_destroy_time_editor(showed_window,&time_editor); - -} -END_TEST - - -/* ----- Test case for set_ticks -----*/ - -/** - * Purpose: Check that regular ticks values are set and get properly - * Cases considered: - * - Set and get ticks to 45660s using time editor object with time mode. - * - Set and get ticks to 124860s using time editor object with duration mode. - */ -START_TEST (test_set_ticks_regular) -{ - guint initial_ticks; - guint ticks; - HildonTimeEditor *time_editor = NULL; - - /* Test 1: Set tick to 45660 seconds to test set_ticks */ - - initial_ticks=45660; - time_editor = create_and_show_time_editor(showed_window,FALSE,FALSE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d",initial_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 2: Set tick to 124860 seconds to test set_ticks */ - - initial_ticks=124860; - - time_editor = create_and_show_time_editor(showed_window,FALSE,TRUE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d",initial_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - -} -END_TEST - -/** - * Purpose: Check that limit ticks values are set and get properly - * Cases considered: - * - Set and get ticks to 0s using time editor object with time mode. - * - Set and get ticks to 86399s using time editor object with time mode. 86399 seconds are 23h 59m 59s. - * - Set and get ticks to 0s using time editor object with duration mode. - * - Set and get ticks to 359999s using time editor object with duration mode. 359999 seconds are 99:59:59. - */ -START_TEST (test_set_ticks_limits) -{ - guint initial_ticks; - guint ticks; - HildonTimeEditor *time_editor = NULL; - - /* Test 1: Set ticks to 0 seconds to test set_ticks with */ - - initial_ticks=0; - time_editor = create_and_show_time_editor(showed_window,FALSE,FALSE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d",initial_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 2: Set ticks to 86399 seconds to test set_ticks */ - initial_ticks=86399; - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d",initial_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 3: Set ticks to 0 seconds to test set_ticks */ - - initial_ticks=0; - time_editor = create_and_show_time_editor(showed_window,FALSE,TRUE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d",initial_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 4: Set ticks to 359999 seconds to test set_ticks */ - - initial_ticks=359999; - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d",initial_ticks,ticks); - remove_and_destroy_time_editor(showed_window,&time_editor); - -} -END_TEST - -/** - * Purpose: Check that invalid ticks values are set and get properly. In this tests we'll test several invalid - * values with the same case because the "mod" operator will define the time set. - * Cases considered: - * - Set and get ticks to 86400s using time editor object with time mode. 86399 seconds are 23h 59m 59s. - * - Set and get ticks to 360000s using time editor object with time mode. - * - Set and get ticks to 90060s using time editor object with time. - * - Set and get ticks to 360000s using time editor object with duration mode. 359999 seconds are 99:59:59. - * - Set and get ticks to 654333s using time editor object with duration mode. - * - Set ticks on NULL object. - */ -START_TEST (test_set_ticks_invalid) -{ - guint initial_ticks; - guint expected_ticks; - guint ticks; - HildonTimeEditor *time_editor = NULL; - - initial_ticks=86400; - expected_ticks=82800; - - /* Test 1: Set ticks to 86400 seconds to test set_ticks */ - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( expected_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d and result is %d", - initial_ticks,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 2: Set ticks to 360000 seconds to test set_ticks */ - initial_ticks=360001; - expected_ticks=82801; - - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( expected_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d and result is %d", - initial_ticks,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 3: Set ticks to 90060 seconds to test set_ticks */ - initial_ticks=90060; - expected_ticks=82860; - - time_editor = create_and_show_time_editor(showed_window,TRUE,FALSE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( expected_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d and result is %d", - initial_ticks,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 4: Set ticks to 360000 seconds to test set_ticks */ - - initial_ticks=360000; - expected_ticks=359999; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( expected_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d and result is %d", - initial_ticks,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 5: Set ticks to 654333 seconds to test set_ticks */ - - initial_ticks=654333; - expected_ticks=359999; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,initial_ticks); - - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( expected_ticks!=ticks ), - "hildon-time-editor: set_ticks or get_ticks failed with %d. Expected result is %d and result is %d", - initial_ticks,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 6: Set initial_ticks on NULL */ - hildon_time_editor_set_ticks(NULL,initial_ticks); -} -END_TEST - - -/* ----- Test case for set_duration_min_set_duration_max -----*/ - -/** - * Purpose: Check that regular minimum/maximum values are set/get properly and check that set_duration_mode works well, - * because min and max can not be set without duration mode set. - * Cases considered: - * - Set and get minimum duration to 100000 having ticks under 100000 using time editor object with duration mode. - * - Set and get minimum duration to 100000 having ticks over 100000 using time editor object with duration mode. - * - Set and get maximum duration to 200000 having ticks under 200000 using time editor object with duration mode. - * - Set and get maximum duration to 200000 having ticks over 200000 using time editor object with duration mode. - */ -START_TEST (test_set_duration_min_set_duration_max_regular) -{ - guint initial_duration_min; - guint duration_min; - guint initial_duration_max; - guint duration_max; - guint expected_ticks; - guint ticks; - HildonTimeEditor *time_editor = NULL; - - time_editor = create_and_show_time_editor(showed_window,FALSE,TRUE); - /* Initialize values in order to avoid side effects from previous tests */ - hildon_time_editor_set_duration_min(time_editor,MIN_DURATION); - hildon_time_editor_set_duration_max(time_editor,MAX_DURATION); - - /* set_min tests*/ - - /* Test 1: Set and get minimum duration to 100000 having ticks under 100000 using time editor object with duration mode. */ - initial_duration_min=100000; - expected_ticks=initial_duration_min; - - hildon_time_editor_set_ticks(time_editor,initial_duration_min-1000); - hildon_time_editor_set_duration_min(time_editor,initial_duration_min); - duration_min = hildon_time_editor_get_duration_min(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_duration_min!=duration_min) | (ticks!=expected_ticks), - "hildon-time-editor: set_duration_min or get_duration_min failed with %d. Expected result is %d. Set ticks to %d, expected ticks are %d and result is %d", - initial_duration_min,duration_min,initial_duration_min-1000,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 2: Set and get minimum duration to 100000 having ticks over 100000 using time editor object with duration mode.*/ - initial_duration_min=100000; - expected_ticks=initial_duration_min+980; - - time_editor = create_and_show_time_editor(showed_window,FALSE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_min(time_editor,initial_duration_min); - duration_min = hildon_time_editor_get_duration_min(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_duration_min!=duration_min) | (ticks!=expected_ticks), - "hildon-time-editor: set_duration_min or get_duration_min failed with %d. Expected result is %d. Set ticks to %d and result is %d", - initial_duration_min,duration_min,ticks,expected_ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - - /* Test 3: Set and get maximum duration to 200000 having ticks under 200000 using time editor object with duration mode. */ - initial_duration_max=200000; - expected_ticks=initial_duration_max-1040; - time_editor = create_and_show_time_editor(showed_window,FALSE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_max(time_editor,initial_duration_max); - duration_max = hildon_time_editor_get_duration_max(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_duration_max!=duration_max) | (ticks!=expected_ticks), - "hildon-time-editor: set_duration_max or get_duration_max failed with %d. Expected result is %d. Set ticks to %d and result is %d", - initial_duration_max,duration_max,ticks,expected_ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 4: Set and get maximum duration to 200000 having ticks over 200000 using time editor object with duration mode.*/ - initial_duration_max=200000; - expected_ticks=initial_duration_max+1000; - time_editor = create_and_show_time_editor(showed_window,FALSE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_max(time_editor,initial_duration_max); - duration_max = hildon_time_editor_get_duration_max(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_duration_max!=duration_max) | (ticks!=initial_duration_max), - "hildon-time-editor: set_duration_max or get_duration_max failed with %d. Expected result is %d. Set ticks to %d, expected result is %d and result is %d", - initial_duration_max,duration_max,expected_ticks,initial_duration_max,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - -} -END_TEST - - -/** - * Purpose: Check that limits duration minimum/maximum values are set and get properly. - * Cases considered: - * - Set and get minimum duration to MIN_DURATION having ticks over MIN_DURATION using time editor object with duration mode. - * - Set and get maximum duration to MAX_DURATION having ticks under MAX_DURATION. - * using time editor object with duration mode. 359940 seconds are 99:59:00. - * - Set and get maximum duration to MIN_DURATION having ticks over MIN_DURATION using time editor object with duration mode. - * - Set and get minimum duration to MAX_DURATION having ticks under MAX_DURATION. - * using time editor object with duration mode. 359999 seconds are 99:59:59. - */ -START_TEST (test_set_duration_min_set_duration_max_limits) -{ - guint initial_duration_min; - guint duration_min; - guint initial_duration_max; - guint duration_max; - guint expected_ticks; - guint ticks; - HildonTimeEditor *time_editor = NULL; - - - /* Test 1: Set minimum duration to MAX_DURATION seconds having ticks under MAX_DURATION. */ - expected_ticks=MIN_DURATION+1; - initial_duration_min=MIN_DURATION; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_min(time_editor,initial_duration_min); - duration_min = hildon_time_editor_get_duration_min(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_duration_min!=duration_min) | (ticks!=expected_ticks), - "hildon-time-editor: set_duration_min or get_duration_min failed with %d. Expected result is %d. Set ticks to %d and result is %d", - initial_duration_min,duration_min,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 2: Set maximum duration to MAX_DURATION seconds having ticks under MAX_DURATION. */ - expected_ticks=MAX_DURATION-59; - initial_duration_max=MAX_DURATION; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_max(time_editor,initial_duration_max); - duration_max = hildon_time_editor_get_duration_max(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_duration_max!=duration_max) | (ticks!=expected_ticks), - "hildon-time-editor: set_duration_max or get_duration_max failed with %d. Expected result is %d. Set ticks to %d and result is %d", - initial_duration_max,duration_max,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 3: Set and get maximum duration to MIN_DURATION having ticks over MIN_DURATION - using time editor object with duration mode. */ - expected_ticks=MIN_DURATION+1; - initial_duration_max=MIN_DURATION; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_max(time_editor,initial_duration_max); - duration_max = hildon_time_editor_get_duration_max(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_duration_max!=duration_max) | (ticks!=MIN_DURATION), - "hildon-time-editor: set_duration_max or get_duration_max failed with %d. Expected result is %d. Set ticks to %d and result is %d", - initial_duration_max,duration_max,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 4: Set and get minimum duration to MIN_DURATION having ticks over MIN_DURATION - using time editor object with duration mode. */ - expected_ticks=MAX_DURATION-1; - initial_duration_min=MAX_DURATION; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_min(time_editor,initial_duration_min); - duration_min = hildon_time_editor_get_duration_min(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( initial_duration_min!=duration_min) | (ticks!=MAX_DURATION), - "hildon-time-editor: set_duration_min or get_duration_min failed with %d. Expected result is %d. Set ticks to %d and result is %d", - initial_duration_min,duration_min,ticks,MAX_DURATION); - - remove_and_destroy_time_editor(showed_window,&time_editor); - -} -END_TEST - -/** - * Purpose: Check that invalid minimum/maximum duration values are set and get properly. - * Cases considered: - * - Set duration_min on NULL object. - * - Set and get minimum duration to MAX_DURATION+1 using time editor object with duration mode - * setting ticks previously with a value under MAX_DURATION. - * - Set and get minimum duration to MAX_DURATION+1 using time editor object with duration mode - * setting ticks previously with a value over MAX_DURATION. - * - Set duration_max on NULL object. - * - Set and get maximum duration to MAX_DURATION+1 using time editor object with duration mode - * setting ticks previously with a value under MAX_DURATION. - * - Set and get maximum duration to MAX_DURATION+1 using time editor object with duration mode - * setting ticks previously with a value over MAX_DURATION. - */ -START_TEST (test_set_duration_min_set_duration_max_invalid) -{ - guint initial_duration_min; - guint expected_duration_min; - guint duration_min; - guint initial_duration_max; - guint expected_duration_max; - guint duration_max; - guint expected_ticks; - guint ticks; - HildonTimeEditor *time_editor = NULL; - - - /* Test 1: Set minimum duration on NULL object */ - hildon_time_editor_set_duration_min(NULL,MIN_DURATION); - - /* Test 2: Set minimum duration to MAX_DURATION+1 seconds to test set_duration_min */ - initial_duration_min=MAX_DURATION+1; - expected_duration_min=MAX_DURATION+1; - expected_ticks=MAX_DURATION-1; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_min(time_editor,initial_duration_min); - duration_min = hildon_time_editor_get_duration_min(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( expected_duration_min!=duration_min) | (ticks!=MAX_DURATION), - "hildon-time-editor: set_duration_min or get_duration_min failed with %d. Expected result is %d and result is %d. Set ticks to %d, expected result is %d and result is %d", - initial_duration_min,duration_min,expected_duration_min,expected_ticks,MAX_DURATION,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 3: Set minimum duration to MAX_DURATION+1 seconds to test set_duration_min */ - initial_duration_min=MAX_DURATION+1; - expected_duration_min=MAX_DURATION+1; - expected_ticks=MAX_DURATION+2; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_min(time_editor,initial_duration_min); - duration_min = hildon_time_editor_get_duration_min(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( expected_duration_min!=duration_min) | (ticks!=MAX_DURATION), - "hildon-time-editor: set_duration_min or get_duration_min failed with %d. Expected result is %d and result is %d. Set ticks to %d, expected result is %d and result is %d", - initial_duration_min,duration_min,expected_duration_min,expected_ticks,MAX_DURATION,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 4: Set maximum duration on NULL object */ - hildon_time_editor_set_duration_max(NULL,MAX_DURATION); - - /* Test 5: Set maximum duration to MAX_DURATION+1 seconds to test set_duration_max settings ticks under MAX_DURATION*/ - initial_duration_max=MAX_DURATION+1; - expected_duration_max=MAX_DURATION; - expected_ticks=MAX_DURATION-59; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_max(time_editor,initial_duration_max); - duration_max = hildon_time_editor_get_duration_max(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if(( expected_duration_max!=duration_max) | (ticks!=expected_ticks), - "hildon-time-editor: set_duration_max or get_duration_max failed with %d. Expected result is %d and result is %d. Set ticks to %d, expected result is %d and result is %d", - initial_duration_max,duration_max,expected_duration_max,expected_ticks,expected_ticks,ticks); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Initialize values in order to avoid side effects from previous tests */ - initial_duration_max=MAX_DURATION+1; - expected_duration_max=MAX_DURATION; - expected_ticks=MAX_DURATION+1; - - /* Test 6: Set maximum duration to MAX_DURATION+1 seconds to test set_duration_max setting ticks over MAX_DURATION */ - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_max(time_editor,initial_duration_max); - duration_max = hildon_time_editor_get_duration_max(time_editor); - ticks = hildon_time_editor_get_ticks(time_editor); - fail_if(( expected_duration_max!=duration_max), - "hildon-time-editor: set_duration_max or get_duration_max failed with %d. Expected result is %d and result is %d. Set ticks to %d, expected result is %d and result is %d", - initial_duration_max,duration_max,expected_duration_max,expected_ticks,MAX_DURATION,ticks); - - /* fail_if(( expected_duration_max!=duration_max) | (ticks!=MAX_DURATION), - "hildon-time-editor: set_duration_max or get_duration_max failed with %d. Expected result is %d and result is %d. Set ticks to %d, expected result is %d and result is %d", - initial_duration_max,duration_max,expected_duration_max,expected_ticks,MAX_DURATION,ticks); - */ - remove_and_destroy_time_editor(showed_window,&time_editor); - - -} -END_TEST - -/* ----- Test case for set_duration_range -----*/ - -/** - * Purpose: Check that regular range values are set and get properly - * Cases considered: - * - Set and get duration range (100000,200000) having ticks under 100000 using time editor object with duration mode. - * - Set and get duration range (100000,200000) having ticks between 100000 and 200000 using time editor object with duration mode. - * - Set and get duration range (100000,200000) having ticks over 200000 using time editor object with duration mode. - * - Set and get duration range (100000,100000) having ticks under 100000 using time editor object with duration mode. - * - Set and get duration range (100000,100000) having ticks equal to 100000 using time editor object with duration mode. - * - Set and get duration range (100000,100000) having ticks over 100000 using time editor object with duration mode. - * - */ -START_TEST (test_set_duration_range_regular) -{ - guint initial_duration_min; - guint initial_duration_max; - guint duration_min; - guint duration_max; - guint expected_ticks; - guint ticks; - HildonTimeEditor *time_editor = NULL; - - /* Test 1: Set duration range to (100000,200000) seconds to test set_duration_range having ticks under 100000 */ - initial_duration_min=100000; - initial_duration_max=200000; - expected_ticks=90000; - - /* Initialize values in order to avoid side effects from previous tests */ - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_min!=duration_min) | (initial_duration_max!=duration_max) | ( ticks!=initial_duration_min )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,initial_duration_max,duration_min,duration_max,ticks,initial_duration_min); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 2: Set duration range to (100000,200000) seconds to test set_duration_range having ticks between 100000 and 200000 */ - initial_duration_min=100000; - initial_duration_max=200000; - expected_ticks=150000; - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_min!=duration_min) | (initial_duration_max!=duration_max) | ( ticks!=initial_duration_min )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,initial_duration_max,duration_min,duration_max,ticks,initial_duration_min); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 3: Set duration range to (100000,200000) seconds to test set_duration_range having ticks over 200000*/ - initial_duration_min=100000; - initial_duration_max=200000; - expected_ticks=220000; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_min!=duration_min) | (initial_duration_max!=duration_max) | ( ticks!=initial_duration_min )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,initial_duration_max,duration_min,duration_max,ticks,initial_duration_min); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 4: Set duration range to (100000,100000) seconds to test set_duration_range having ticks under 100000 */ - initial_duration_min=100000; - initial_duration_max=100000; - expected_ticks=90000; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_min!=duration_min) | (initial_duration_max!=duration_max) | ( ticks!=initial_duration_min )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,initial_duration_max,duration_min,duration_max,ticks,initial_duration_min); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 5: Set duration range to (100000,100000) seconds to test set_duration_range having ticks equal to 100000 */ - initial_duration_min=100000; - initial_duration_max=100000; - expected_ticks=100000; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_min!=duration_min) | (initial_duration_max!=duration_max) | ( ticks!=initial_duration_min )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,initial_duration_max,duration_min,duration_max,ticks,initial_duration_min); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 6: Set duration range to (100000,100000) seconds to test set_duration_range having ticks over 100000 */ - initial_duration_min=100000; - initial_duration_max=100000; - expected_ticks=120000; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_min!=duration_min) | (initial_duration_max!=duration_max) | ( ticks!=initial_duration_min )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,initial_duration_max,duration_min,duration_max,ticks,initial_duration_min); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - -} -END_TEST - -/** - * Purpose: Check that limits range values are set and get properly - * Cases considered: - * - Set and get duration range to (MIN_DURATION,MAX_DURATION) having ticks between MIN_DURATION and MAX_DURATION - * using time editor object with duration mode. - * - Set and get duration range to (MIN_DURATION,MIN_DURATION) having ticks over MIN_DURATION - * using time editor object with duration mode. - * - Set and get duration range to (MAX_DURATION,MAX_DURATION) having ticks under MAX_DURATION - * using time editor object with duration mode. - * - */ -START_TEST (test_set_duration_range_limits) -{ - guint initial_duration_min; - guint initial_duration_max; - guint duration_min; - guint duration_max; - guint expected_ticks; - guint ticks; - HildonTimeEditor *time_editor = NULL; - - - /* Test 1: Set duration range to (MIN_DURATION,MAX_DURATION) seconds to test set_duration_range having ticks under MIN_DURATION */ - initial_duration_min=MIN_DURATION; - initial_duration_max=MAX_DURATION; - expected_ticks=MIN_DURATION+1; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - /* Initialize values in order to avoid side effects from previous tests */ - hildon_time_editor_set_duration_min(time_editor,MIN_DURATION); - hildon_time_editor_set_duration_max(time_editor,MAX_DURATION); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_min!=duration_min) | (initial_duration_max!=duration_max) | ( ticks!=initial_duration_min )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,initial_duration_max,duration_min,duration_max,ticks,initial_duration_min); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 2: Set duration range to (MIN_DURATION,MIN_DURATION) seconds to test set_duration_range having ticks over MIN_DURATION */ - initial_duration_min=MIN_DURATION; - initial_duration_max=MIN_DURATION; - expected_ticks=MIN_DURATION+1; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_min!=duration_min) | (initial_duration_max!=duration_max) | ( ticks!=initial_duration_min )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,initial_duration_max,duration_min,duration_max,ticks,initial_duration_min); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 3: Set duration range to (MAX_DURATION,MAX_DURATION) seconds to test set_duration_range having ticks under MAX_DURATION */ - initial_duration_min=MAX_DURATION; - initial_duration_max=MAX_DURATION; - expected_ticks=MAX_DURATION-1; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_min!=duration_min) | (initial_duration_max!=duration_max) | ( ticks!=initial_duration_min )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,initial_duration_max,duration_min,duration_max,ticks,initial_duration_min); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - -} -END_TEST - -/** - * Purpose: Check that invalid range values are set and get properly - * Cases considered: - * - Set duration_range on NULL object. - * - Set and get duration range to (MAX_DURATION,MIN_DURATION) using time editor object with duration mode. - * - Set and get duration range to (MIN_DURATION,MAX_DURATION+1) having ticks between MIN_DURATION and MAX_DURATION - * using time editor object with duration mode. - * - Set and get duration range to (MAX_DURATION+1,MIN_DURATION) using time editor object with duration mode. - * - Set and get duration range to (MAX_DURATION+1,MAX_DURATION+3) - * using time editor object with duration mode. - * - Set and get duration range to (MAX_DURATION+3,MAX_DURATION+1) - * using time editor object with duration mode. - * - */ -START_TEST (test_set_duration_range_invalid) -{ - guint initial_duration_min; - guint initial_duration_max; - guint duration_min; - guint duration_max; - guint expected_ticks; - guint ticks; - HildonTimeEditor *time_editor = NULL; - - - /* Test 1: Set duration range on NULL */ - hildon_time_editor_set_duration_range(NULL,MIN_DURATION,MAX_DURATION); - - /* Test 2: Set duration range to (MAX_DURATION,MIN_DURATION) seconds to test set_duration_range */ - initial_duration_min=MAX_DURATION; - initial_duration_max=MIN_DURATION; - expected_ticks=MIN_DURATION+1; - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (MIN_DURATION!=duration_min) | (MAX_DURATION!=duration_max) | ( ticks!=MIN_DURATION )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - MIN_DURATION,MAX_DURATION,duration_min,duration_max,ticks,MIN_DURATION); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 3: Set duration range to (MIN_DURATION,MAX_DURATION+1) seconds to test set_duration_range */ - initial_duration_min=MIN_DURATION; - initial_duration_max=MAX_DURATION+1; - expected_ticks=MAX_DURATION-59; - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (MIN_DURATION!=duration_min) | (MAX_DURATION!=duration_max) | ( ticks!=MIN_DURATION )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - MIN_DURATION,MAX_DURATION,duration_min,duration_max,ticks,MIN_DURATION); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 4: Set duration range to (MAX_DURATION+1,MIN_DURATION) seconds to test set_duration_range */ - initial_duration_min=MAX_DURATION+1; - initial_duration_max=MIN_DURATION; - expected_ticks=MIN_DURATION-1; - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - - fail_if( ( (MIN_DURATION!=duration_min) | (MAX_DURATION!=duration_max) ), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). ", - MIN_DURATION,MAX_DURATION,duration_min,duration_max); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - - /* Test 5: Set duration range to (MAX_DURATION+1,MIN_DURATION+3) seconds to test set_duration_range */ - initial_duration_min=MAX_DURATION+1; - initial_duration_max=MAX_DURATION+3; - expected_ticks=MAX_DURATION+1; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - -/* fail_if( ( (initial_duration_min!=duration_min) | (MAX_DURATION!=duration_max) | ( ticks!=MAX_DURATION )), */ -/* "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", */ -/* initial_duration_min,MAX_DURATION,duration_min,duration_max,ticks,MAX_DURATION); */ - - fail_if( ( (initial_duration_min!=duration_min) | (MAX_DURATION!=duration_max) ), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_min,MAX_DURATION,duration_min,duration_max,ticks,MAX_DURATION); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - /* Test 6: Set duration range to (MAX_DURATION+3,MIN_DURATION+1) seconds to test set_duration_range */ - initial_duration_min=MAX_DURATION+3; - initial_duration_max=MAX_DURATION+1; - expected_ticks=MAX_DURATION+1; - - time_editor = create_and_show_time_editor(showed_window,TRUE,TRUE); - - hildon_time_editor_set_ticks(time_editor,expected_ticks); - hildon_time_editor_set_duration_range(time_editor,initial_duration_min,initial_duration_max); - hildon_time_editor_get_duration_range(time_editor,&duration_min,&duration_max); - ticks = hildon_time_editor_get_ticks(time_editor); - - fail_if( ( (initial_duration_max!=duration_min) | (MAX_DURATION!=duration_max) | ( ticks!=MAX_DURATION )), - "hildon-time-editor: set_duration_range or get_duration_range failed with (minimum,maximum) as (%d,%d). Expected range is (%d,%d). Set ticks to %d and expected ticks are %d ", - initial_duration_max,MAX_DURATION,duration_min,duration_max,ticks,MAX_DURATION); - - remove_and_destroy_time_editor(showed_window,&time_editor); - - -} -END_TEST - - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_time_editor_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonTimeEditor"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_time"); - TCase *tc2 = tcase_create("set_ticks"); - TCase *tc3 = tcase_create("set_duration_min_set_duration_max"); - TCase *tc4 = tcase_create("set_duration_range"); - - /* Create test case for hildon_time_editor_set_time and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_time_editor, fx_teardown_default_time_editor); - tcase_add_test(tc1, test_set_time_regular); - tcase_add_test(tc1, test_set_time_limits); - tcase_add_test(tc1, test_set_time_invalid); - suite_add_tcase (s, tc1); - - /* Create test case for hildon_time_editor_set_ticks and add it to the suite */ - tcase_add_checked_fixture(tc2, fx_setup_default_time_editor, fx_teardown_default_time_editor); - tcase_add_test(tc2, test_set_ticks_regular); - tcase_add_test(tc2, test_set_ticks_limits); - tcase_add_test(tc2, test_set_ticks_invalid); - suite_add_tcase (s, tc2); - - /* Create test case for hildon_time_editor_set_duration_max and add it to the suite */ - tcase_add_checked_fixture(tc3, fx_setup_default_time_editor, fx_teardown_default_time_editor); - tcase_add_test(tc3, test_set_duration_min_set_duration_max_regular); - tcase_add_test(tc3, test_set_duration_min_set_duration_max_limits); - tcase_add_test(tc3, test_set_duration_min_set_duration_max_invalid); - suite_add_tcase (s, tc3); - - /* Create test case for hildon_time_editor_set_duration_range and add it to the suite */ - tcase_add_checked_fixture(tc4, fx_setup_default_time_editor, fx_teardown_default_time_editor); - tcase_add_test(tc4, test_set_duration_range_regular); - tcase_add_test(tc4, test_set_duration_range_limits); - tcase_add_test(tc4, test_set_duration_range_invalid); - suite_add_tcase (s, tc4); - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-time-picker.c b/tests/check-hildon-time-picker.c deleted file mode 100644 index 7dfacb0..0000000 --- a/tests/check-hildon-time-picker.c +++ /dev/null @@ -1,277 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-window.h> -#include <hildon/hildon-time-picker.h> - -/* -------------------- Fixtures -------------------- */ - -static HildonTimePicker *time_picker = NULL; -static HildonWindow *tp_window = NULL; - -static void -fx_setup_default_time_picker () -{ - int argc = 0; - gtk_init(&argc, NULL); - - tp_window = HILDON_WINDOW(hildon_window_new()); - /* Check window object has been created properly */ - fail_if(!HILDON_IS_WINDOW(tp_window), - "hildon-time-picker: Window creation failed."); - - time_picker = HILDON_TIME_PICKER(hildon_time_picker_new(GTK_WINDOW(tp_window))); - - /* Check time_picker object has been created properly */ - fail_if(!HILDON_IS_TIME_PICKER(time_picker), - "hildon-time-picker: Creation failed."); - - /* Displays the widget and the window */ - show_all_test_window (GTK_WIDGET (tp_window)); - show_all_test_window (GTK_WIDGET (time_picker)); - -} - -static void -fx_teardown_default_time_picker () -{ - gtk_widget_destroy (GTK_WIDGET (time_picker)); - gtk_widget_destroy (GTK_WIDGET (tp_window)); -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_time -----*/ - -/** - * Purpose: Check that regular time values are set and get properly - * Cases considered: - * - Set and get time to 5h 30m using time picker object. - * - Set and get time to 18h 2m using time picker object. - */ -START_TEST (test_set_time_regular) -{ - guint hours; - guint minutes; - guint ret_hours; - guint ret_minutes; - - /* Check time_picker object has been created properly */ - fail_if(!HILDON_IS_TIME_PICKER(time_picker), - "hildon-time-picker: Creation failed."); - - /* Test 1: Set and get time to 5h 30m using time picker object. */ - hours = 5; - minutes = 30; - - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (hours != ret_hours || minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, ret_hours, ret_minutes); - - /* Test 2: Set and get time to 18h 2m using time picker object. */ - hours = 18; - minutes = 2; - - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (hours != ret_hours || minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, ret_hours, ret_minutes); -} -END_TEST - -/** - * Purpose: Check that limit time values are set and get properly - * Cases considered: - * - Set and get time to 0h 0m using time picker object. - * - Set and get time to 0h 59m using time picker object. - * - Set and get time to 12h 59m using time picker object. - * - Set and get time to 23h 59m using time picker object. - */ -START_TEST (test_set_time_limits) -{ - guint hours; - guint minutes; - guint ret_hours; - guint ret_minutes; - - /* Check time_picker object has been created properly */ - fail_if(!HILDON_IS_TIME_PICKER(time_picker), - "hildon-time-picker: Creation failed."); - - /* Test 1: Set and get time to 0h 0m using time picker object. */ - hours = 0; - minutes = 0; - - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (hours != ret_hours || minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, ret_hours, ret_minutes); - - /* Test 2: Set and get time to 0h 59m using time picker object. */ - hours = 0; - minutes = 59; - - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (hours != ret_hours || minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, ret_hours, ret_minutes); - - /* Test 3: Set and get time to 12h 59m using time picker object. */ - hours = 12; - minutes = 59; - - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (hours != ret_hours || minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, ret_hours, ret_minutes); - - /* Test 4: Set and get time to 23h 59m using time picker object. */ - hours = 23; - minutes = 59; - - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (hours != ret_hours || minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, ret_hours, ret_minutes); -} -END_TEST - -/** - * Purpose: Check that limit time values are set and get properly - * Cases considered: - * - Set and get time using NULL time picker. - * - Set and get time to 0h 60m using time picker object. - * - Set and get time to 24h 0m using time picker object. - * - Set and get time to 24h 60m using time picker object. - * - Set and get time to 16000h 15533m using time picker object. - */ -START_TEST (test_set_time_invalid) -{ - guint hours; - guint minutes; - guint ret_hours; - guint ret_minutes; - guint expected_hours; - guint expected_minutes; - - /* Check time_picker object has been created properly */ - fail_if(!HILDON_IS_TIME_PICKER(time_picker), - "hildon-time-picker: Creation failed."); - - hours = 0; - minutes = 60; - expected_hours=1; - expected_minutes=0; - - /* Test 1: Set and get time using NULL time picker */ - hildon_time_picker_set_time(NULL,hours,minutes); - hildon_time_picker_get_time(NULL,&ret_hours,&ret_minutes); - - /* Test 2: Set and get time to 0h 60m using time picker object. */ - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes); - - /* Test 3: Set and get time to 24h 0m using time picker object. */ - hours = 24; - minutes = 0; - expected_hours=0; - expected_minutes=0; - - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes); - - /* Test 4: Set and get time to 24h 60m using time picker object. */ - hours = 24; - minutes = 60; - expected_hours=1; - expected_minutes=0; - - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes); - - /* Test 5: Set and get time to 16000h 15533m using time picker object.*/ - hours = 16000; - minutes = 15533; - expected_hours=10; - expected_minutes=53; - - hildon_time_picker_set_time(time_picker,hours,minutes); - hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes); - - fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes, - "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)", - hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_time_picker_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonTimePicker"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_time"); - - /* Create test case for hildon_time_picker_set_time and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_time_picker, fx_teardown_default_time_picker); - tcase_add_test(tc1, test_set_time_regular); - tcase_add_test(tc1, test_set_time_limits); - tcase_add_test(tc1, test_set_time_invalid); - suite_add_tcase(s, tc1); - - /* Return created suite */ - return s; -} diff --git a/tests/check-hildon-volumebar-range.c b/tests/check-hildon-volumebar-range.c deleted file mode 100644 index 921ef0a..0000000 --- a/tests/check-hildon-volumebar-range.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkcontainer.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-volumebar-range.h> - -/* Copied from hildon-volumebar-range.h because - there is no way to retrieve this values */ -#define VOLUMEBAR_RANGE_INITIAL_VALUE 50.0 -#define VOLUMEBAR_RANGE_MINIMUM_VALUE 0.0 -#define VOLUMEBAR_RANGE_MAXIMUM_VALUE 100.0 -#define CHANGE_THRESHOLD 0.001 - -/* -------------------- Fixtures -------------------- */ - -static GtkWidget *showed_window = NULL; -static HildonVolumebarRange *volumebar_range = NULL; - -static void -fx_setup_default_volumebar_range () -{ - int argc = 0; - - gtk_init(&argc, NULL); - - volumebar_range = HILDON_VOLUMEBAR_RANGE(hildon_volumebar_range_new(GTK_ORIENTATION_VERTICAL)); - - showed_window = create_test_window (); - - /* This packs the widget into the window (a gtk container). */ - gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (volumebar_range)); - - /* Displays the widget and the window */ - show_all_test_window (showed_window); - - /* Check volumebar range object has been created properly */ - fail_if(!HILDON_VOLUMEBAR_RANGE(volumebar_range), - "hildon-volumebar-range: Creation failed."); -} - -static void -fx_teardown_default_volumebar_range () -{ - - /* Destroy the window */ - gtk_widget_destroy (showed_window); -} - - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set/get_level -----*/ - -/** - * Purpose: Check level usage - * Cases considered: - * - Set level over the threshold limit - * - Set level under the threshold limit. - */ -START_TEST (test_set_get_level_regular) -{ - gdouble old_level, level, ret_level; - - /* Test1: set level so change is over the threshold limit */ - level = VOLUMEBAR_RANGE_INITIAL_VALUE + 1.0 + CHANGE_THRESHOLD; - hildon_volumebar_range_set_level(volumebar_range, level); - ret_level = hildon_volumebar_range_get_level(volumebar_range); - fail_if(ret_level != level, - "hildon-volumebar-range: Set level to %.5f, but get level returned %.5f", - level, ret_level); - - /* Test2: set level so change is under the threshold limit */ - old_level = ret_level; - level += (gdouble) (CHANGE_THRESHOLD/2.0); - hildon_volumebar_range_set_level(volumebar_range, level); - ret_level = hildon_volumebar_range_get_level(volumebar_range); - fail_if(ret_level == level, - "hildon-volumebar-range: Set level to %.5f when current level is %.5f, but get level returned %.5f", - level, old_level, ret_level); -} -END_TEST - -/** - * Purpose: Test handling of limit values - * Cases considered: - * - Set level to VOLUMEBAR_RANGE_MINIMUM_VALUE - * - Set level to VOLUMEBAR_RANGE_MAXIMUM_VALUE - */ -START_TEST (test_set_get_level_limits) -{ - gdouble level, ret_level; - - /* Test1: Set level to minimum allowed (first set it the a different value) */ - level = (VOLUMEBAR_RANGE_MINIMUM_VALUE - VOLUMEBAR_RANGE_MINIMUM_VALUE) / 2.0; - hildon_volumebar_range_set_level(volumebar_range, level); - level = VOLUMEBAR_RANGE_MINIMUM_VALUE; - hildon_volumebar_range_set_level(volumebar_range, level); - ret_level = hildon_volumebar_range_get_level(volumebar_range); - fail_if(ret_level != level, - "hildon-volumebar-range: Set level to %.5f, but get level returned %.5f", - level, ret_level); - - /* Test2: Set level to maximum allowed */ - level = VOLUMEBAR_RANGE_MAXIMUM_VALUE; - hildon_volumebar_range_set_level(volumebar_range, level); - ret_level = hildon_volumebar_range_get_level(volumebar_range); - fail_if(ret_level != level, - "hildon-volumebar-range: Set level to %.5f, but get level returned %.5f", - level, ret_level); -} -END_TEST - -/** - * Purpose: Test handling of invalid values - * Cases considered: - * - Set level under the minimum value - * - Set level over the maximum value - * - Set level with NULL object - * - Get level with NULL object - */ -START_TEST (test_set_get_level_invalid) -{ - gdouble level, ret_level; - - /* Test1: Set level under minimum value */ - level = VOLUMEBAR_RANGE_MINIMUM_VALUE - 1.0 - CHANGE_THRESHOLD; - hildon_volumebar_range_set_level(volumebar_range, level); - ret_level = hildon_volumebar_range_get_level(volumebar_range); - fail_if(ret_level != VOLUMEBAR_RANGE_MINIMUM_VALUE, - "hildon-volumebar-range: Set level to %.5f (under the minimum allowed), and get level returned %.5f", - level, ret_level); - - /* Test2: Set level over maximum value */ - level = VOLUMEBAR_RANGE_MAXIMUM_VALUE + 1.0 + CHANGE_THRESHOLD; - hildon_volumebar_range_set_level(volumebar_range, level); - ret_level = hildon_volumebar_range_get_level(volumebar_range); - fail_if(ret_level != VOLUMEBAR_RANGE_MAXIMUM_VALUE, - "hildon-volumebar-range: Set level to %.5f (greater than maximum allowed), and get level returned %.5f", - level, ret_level); - - /* Test3: Set level with NULL object */ - hildon_volumebar_range_set_level(NULL, level); - - /* Test4: Get level with NULL object */ - hildon_volumebar_range_get_level(NULL); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_volumebar_range_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonVolumebarRange"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_get_level"); - - /* Create test case for set/get_mute and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_volumebar_range, fx_teardown_default_volumebar_range); - tcase_add_test(tc1, test_set_get_level_regular); - tcase_add_test(tc1, test_set_get_level_limits); - tcase_add_test(tc1, test_set_get_level_invalid); - suite_add_tcase (s, tc1); - - /* Return created suite */ - return s; -} - - diff --git a/tests/check-hildon-volumebar.c b/tests/check-hildon-volumebar.c deleted file mode 100644 index 1bc03c2..0000000 --- a/tests/check-hildon-volumebar.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-window.h> -#include <hildon/hildon-volumebar.h> -#include <hildon/hildon-hvolumebar.h> -#include <hildon/hildon-vvolumebar.h> - -/* -------------------- Fixtures -------------------- */ - -static HildonVolumebar *volumebar = NULL; -static HildonWindow *window = NULL; - -static void -fx_setup_hvolumebar () -{ - int argc = 0; - - gtk_init(&argc, NULL); - - volumebar = HILDON_VOLUMEBAR(hildon_hvolumebar_new()); - - /* Check volumebar object has been created properly */ - fail_if(!HILDON_VOLUMEBAR(volumebar), - "hildon-volumebar: Creation failed."); - - /* Add volumebar to a window to avoid gtk warnings when - trying to set focus to parent window */ - window = HILDON_WINDOW(hildon_window_new()); - - /* Check window object has been created properly */ - fail_if(!HILDON_IS_WINDOW(window), - "hildon-window: Creation failed."); - - gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar)); - - /* Displays the widget and the window */ - show_all_test_window (GTK_WIDGET (window)); -} - -static void -fx_setup_vvolumebar () -{ - int argc = 0; - - gtk_init(&argc, NULL); - - volumebar = HILDON_VOLUMEBAR(hildon_vvolumebar_new()); - - /* Check volumebar object has been created properly */ - fail_if(!HILDON_VOLUMEBAR(volumebar), - "hildon-volumebar: Creation failed."); - - /* Add volumebar to a window to avoid gtk warnings when - trying to set focus to parent window */ - window = HILDON_WINDOW(hildon_window_new()); - - /* Check window object has been created properly */ - fail_if(!HILDON_IS_WINDOW(window), - "hildon-window: Creation failed."); - - gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar)); - - /* Displays the widget and the window */ - show_all_test_window (GTK_WIDGET (window)); -} - -static void -fx_teardown_volumebar() -{ - gtk_widget_destroy (GTK_WIDGET (window)); -} - - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set/get_mute -----*/ - -/** - * Purpose: Check mute usage - * Cases considered: - * - Set mute ON when volumebar is focusable - * - Set mute OFF when volumebar is focusable - * - Set mute ON when volumebar is not focusable - * - Set mute OFF when volumebar is not focusable - */ -START_TEST (test_set_get_mute_regular) -{ - gboolean ret_mute; - GValue value = {0,}; - - /* Test1: Set mute in focusable state */ - g_value_init(&value, G_TYPE_BOOLEAN); - g_value_set_boolean(&value, TRUE); - g_object_set_property(G_OBJECT(volumebar), "can-focus", &value); - hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), TRUE); - ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar)); - fail_if(ret_mute != TRUE, - "hildon-volumebar: Set mute to TRUE (volumebar is focusable), but get mute returned FALSE"); - - /* Test2: Unset mute in focusable state */ - hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), FALSE); - ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar)); - fail_if(ret_mute != FALSE, - "hildon-volumebar: Set mute to FALSE (volumebar is focusable), but get mute returned TRUE"); - - /* Test3: Set mute in not focusable state */ - g_value_set_boolean(&value, FALSE); - g_object_set_property(G_OBJECT(volumebar), "can-focus", &value); - hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), TRUE); - ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar)); - fail_if(ret_mute != TRUE, - "hildon-volumebar: Set mute to TRUE (volumebar is not focusable), but get mute returned FALSE"); - - /* Test4: Unset mute in not focusable state */ - hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), FALSE); - ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar)); - fail_if(ret_mute != FALSE, - "hildon-volumebar: Set mute to FALSE (volumebar is not focusable), but get mute returned TRUE"); - fail_if(gtk_window_get_focus(GTK_WINDOW(window)) != NULL, - "hildon-volumebar: Set mute to FALSE (volumebar is not focusable), but parent window has focused child"); -} -END_TEST - -/** - * Purpose: Test handling of invalid values for get/set_mute interface - * Cases considered: - * - Set mute with NULL volumebar object - * - Get mute with NULL volumebar object - */ -START_TEST (test_set_get_mute_invalid) -{ - /* Check volumebar object has been created properly */ - fail_if(!HILDON_VOLUMEBAR(volumebar), - "hildon-volumebar: Creation failed."); - - /* Test1: Check set mute with NULL volumebar object */ - hildon_volumebar_set_mute(NULL, FALSE); - - /* Test2: Check get mute with NULL volumebar object */ - hildon_volumebar_get_mute(NULL); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_volumebar_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonVolumebar"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_get_mute_hvolumebar"); - TCase *tc2 = tcase_create("set_get_mute_vvolumebar"); - - /* Create test case for set/get_mute (hvolumebar) and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_hvolumebar, fx_teardown_volumebar); - tcase_add_test(tc1, test_set_get_mute_regular); - tcase_add_test(tc1, test_set_get_mute_invalid); - suite_add_tcase (s, tc1); - - /* Create test case for set/get_mute (vvolumebar) and add it to the suite */ - tcase_add_checked_fixture(tc2, fx_setup_vvolumebar, fx_teardown_volumebar); - tcase_add_test(tc2, test_set_get_mute_regular); - tcase_add_test(tc2, test_set_get_mute_invalid); - suite_add_tcase (s, tc2); - - /* Return created suite */ - return s; -} - - diff --git a/tests/check-hildon-weekday-picker.c b/tests/check-hildon-weekday-picker.c deleted file mode 100644 index e641805..0000000 --- a/tests/check-hildon-weekday-picker.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - * This file is a part of hildon tests - * - * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved. - * - * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#include <stdlib.h> -#include <check.h> -#include <gtk/gtkmain.h> -#include "test_suites.h" -#include "check_utils.h" - -#include <hildon/hildon-weekday-picker.h> -#include <hildon/hildon-window.h> -#include <hildon/hildon-caption.h> - -/* -------------------- Fixtures -------------------- */ - -static HildonWeekdayPicker *weekday_picker = NULL; -static GtkWidget *showed_window = NULL; - -static void -fx_setup_default_weekday_picker () -{ - int argc = 0; - - gtk_init(&argc, NULL); - - showed_window = create_test_window (); - - weekday_picker = HILDON_WEEKDAY_PICKER(hildon_weekday_picker_new()); - /* Check weekday_picker object has been created properly */ - fail_if(!HILDON_IS_WEEKDAY_PICKER(weekday_picker), - "hildon-weekday-picker: Creation failed."); - - /* This packs the widget into the window (a gtk container). */ - gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (weekday_picker)); - - /* Displays the widget and the window */ - show_all_test_window (showed_window); - - -} - -static void -fx_teardown_default_weekday_picker () -{ - gtk_widget_destroy (GTK_WIDGET (showed_window)); -} - -/* -------------------- Test cases -------------------- */ - -/* ----- Test case for set_day / isset_day -----*/ - -/** - * Purpose: Check that regular day values are set and get properly - * Cases considered: - * - Set and isset the day "WEDNESDAY" on weekday picker. - * - Set and isset two days (WEDNESDAY and SATURDAY) on weekday picker and check that only the two selected days are set. - */ -START_TEST (test_set_day_regular) -{ - - /* Test 1: Set WEDNESDAY on weekday picker. */ - hildon_weekday_picker_set_day(weekday_picker,G_DATE_WEDNESDAY); - - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY didn't set WEDNESDAY."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY set MONDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_TUESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY set TUESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_THURSDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY set THURSDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_FRIDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY set FRIDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SATURDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY set SATURDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY set SUNDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_BAD_WEEKDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY set G_DATE_BAD_WEEKDAY wrong."); - - hildon_weekday_picker_set_day(weekday_picker,G_DATE_WEDNESDAY); - hildon_weekday_picker_set_day(weekday_picker,G_DATE_SATURDAY); - - /* Test 1: Set WEDNESDAY and SATURDAY on weekday picker. */ - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY and G_DATE_SATURDAY didn't set WEDNESDAY."); - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SATURDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY and G_DATE_SATURDAY didn't set SATURDAY."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_TUESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY and G_DATE_SATURDAY set TUESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_THURSDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY and G_DATE_SATURDAY set THURSDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY and G_DATE_SATURDAY set MONDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_FRIDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY and G_DATE_SATURDAY set FRIDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY and G_DATE_SATURDAY set SUNDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_BAD_WEEKDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_WEDNESDAY and G_DATE_SATURDAY set G_DATE_BAD_WEEKDAY wrong."); - -} -END_TEST - -/** - * Purpose: Check that limit day values are set and get properly - * Cases considered: - * - Set and isset the day "MONDAY". - * - Set and isset the day "SUNDAY". - * - Set SUNDAY and MONDAY on weekday picker and check that the two selected days are set, but the others doesn't be set. - * - Set all days on weekday picker and check that all days are set. - */ -START_TEST (test_set_day_limits) -{ - - hildon_weekday_picker_unset_all(weekday_picker); - - /* Test 1: Set MONDAY on weekday picker. */ - hildon_weekday_picker_set_day(weekday_picker,G_DATE_MONDAY); - - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY didn't set MONDAY."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set SUNDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_TUESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set TUESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set WEDNESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_THURSDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set THURSDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_FRIDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set FRIDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SATURDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set SATURDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_BAD_WEEKDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set G_DATE_BAD_WEEKDAY wrong."); - - hildon_weekday_picker_unset_all(weekday_picker); - - /* Test 2: Set SUNDAY on weekday picker. */ - hildon_weekday_picker_set_day(weekday_picker,G_DATE_SUNDAY); - - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_SUNDAY didn't set SUNDAY."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set MONDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_TUESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set TUESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set WEDNESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_THURSDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set THURSDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_FRIDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set FRIDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SATURDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set SATURDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_BAD_WEEKDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY set G_DATE_BAD_WEEKDAY wrong."); - - hildon_weekday_picker_unset_all(weekday_picker); - - hildon_weekday_picker_set_day(weekday_picker,G_DATE_SUNDAY); - hildon_weekday_picker_set_day(weekday_picker,G_DATE_MONDAY); - - /* Test 3: Set MONDAY and SUNDAY on weekday picker. */ - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY and G_DATE_SUNDAY didn't set MONDAY."); - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY and G_DATE_SUNDAY didn't set SUNDAY."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_TUESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY and G_DATE_SUNDAY set TUESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY and G_DATE_SUNDAY set WEDNESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_THURSDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY and G_DATE_SUNDAY set THURSDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_FRIDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY and G_DATE_SUNDAY set FRIDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SATURDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_MONDAY and G_DATE_SUNDAY set SATURDAY wrong."); - - hildon_weekday_picker_unset_all(weekday_picker); - - /* Test 4: Set all days on weekday picker. */ - hildon_weekday_picker_set_day(weekday_picker,G_DATE_MONDAY); - hildon_weekday_picker_set_day(weekday_picker,G_DATE_TUESDAY); - hildon_weekday_picker_set_day(weekday_picker,G_DATE_WEDNESDAY); - hildon_weekday_picker_set_day(weekday_picker,G_DATE_THURSDAY); - hildon_weekday_picker_set_day(weekday_picker,G_DATE_FRIDAY); - hildon_weekday_picker_set_day(weekday_picker,G_DATE_SATURDAY); - hildon_weekday_picker_set_day(weekday_picker,G_DATE_SUNDAY); - - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day/isset_day all days did not set MONDAY."); - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day/isset_day all days did not set SUNDAY."); - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_TUESDAY), "hildon-weekday-picker: set_day/isset_day all days did not set TUESDAY."); - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day/isset_day all days did not set WEDNESDAY."); - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_THURSDAY), "hildon-weekday-picker: set_day/isset_day all days did not set THURSDAY."); - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_FRIDAY), "hildon-weekday-picker: set_day/isset_day all days did not set FRIDAY."); - fail_if(!hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SATURDAY), "hildon-weekday-picker: set_day/isset_day all days did not set SATURDAY."); - -} -END_TEST - -/** - * Purpose: Check that invalid day values are set and get properly - * Cases considered: - * - Set MONDAY on NULL weekday picker. - * - Set G_DATE_BAD_WEEKDAY on weekday picker. - * - Set 8 on weekday picker. - * - Set -2 on weekday picker. - * - isset_day from NULL weekday picker - */ -START_TEST (test_set_day_invalid) -{ - - hildon_weekday_picker_unset_all(weekday_picker); - - /* Test 1: Set MONDAY on NULL weekday picker. */ - hildon_weekday_picker_set_day(NULL,G_DATE_MONDAY); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day on NULL object set MONDAY wrong"); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day on NULL object set SUNDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day on NULL object set WEDNESDAY wrong."); - - /* Test 2: Set G_DATE_BAD_WEEKDAY on weekday picker. */ - - hildon_weekday_picker_set_day(weekday_picker,G_DATE_BAD_WEEKDAY); - - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_BAD_WEEKDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_BAD_WEEKDAY set G_DATE_BAD_WEEKDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_BAD_WEEKDAY set MONDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_TUESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_BAD_WEEKDAY set TUESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_BAD_WEEKDAY set WEDNESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_THURSDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_BAD_WEEKDAY set THURSDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_FRIDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_BAD_WEEKDAY set FRIDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SATURDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_BAD_WEEKDAY set SATURDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day/isset_day to G_DATE_BAD_WEEKDAY set SUNDAY wrong."); - - /* Test 3: Set 8 on weekday picker. */ - hildon_weekday_picker_set_day(weekday_picker,8); - - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_BAD_WEEKDAY), "hildon-weekday-picker: set_day/isset_day to 8 set G_DATE_BAD_WEEKDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day/isset_day to 8 set MONDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_TUESDAY), "hildon-weekday-picker: set_day/isset_day to 8 set TUESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day/isset_day to 8 set WEDNESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_THURSDAY), "hildon-weekday-picker: set_day/isset_day to 8 set THURSDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_FRIDAY), "hildon-weekday-picker: set_day/isset_day to 8 set FRIDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SATURDAY), "hildon-weekday-picker: set_day/isset_day to 8 set SATURDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day/isset_day to 8 set SUNDAY wrong."); - - /* Test 4: Set -2 on weekday picker. */ - hildon_weekday_picker_set_day(weekday_picker,-2); - - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_BAD_WEEKDAY), "hildon-weekday-picker: set_day/isset_day to -2 set G_DATE_BAD_WEEKDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_MONDAY), "hildon-weekday-picker: set_day/isset_day to -2 set MONDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_TUESDAY), "hildon-weekday-picker: set_day/isset_day to -2 set TUESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_WEDNESDAY), "hildon-weekday-picker: set_day/isset_day to -2 set WEDNESDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_THURSDAY), "hildon-weekday-picker: set_day/isset_day to -2 set THURSDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_FRIDAY), "hildon-weekday-picker: set_day/isset_day to -2 set FRIDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SATURDAY), "hildon-weekday-picker: set_day/isset_day to -2 set SATURDAY wrong."); - fail_if(hildon_weekday_picker_isset_day(weekday_picker,G_DATE_SUNDAY), "hildon-weekday-picker: set_day/isset_day to -2 set SUNDAY wrong."); - - /* Test 4: isset_day from NULL weekday picker. */ - hildon_weekday_picker_isset_day(NULL,G_DATE_BAD_WEEKDAY); -} -END_TEST - -/* ---------- Suite creation ---------- */ - -Suite *create_hildon_weekday_picker_suite() -{ - /* Create the suite */ - Suite *s = suite_create("HildonWeekdayPicker"); - - /* Create test cases */ - TCase *tc1 = tcase_create("set_day"); - - /* Create test case for hildon_weekday_picker_set_day and hildon_weekday_picker_isset_day and add it to the suite */ - tcase_add_checked_fixture(tc1, fx_setup_default_weekday_picker, fx_teardown_default_weekday_picker); - tcase_add_test(tc1, test_set_day_regular); - tcase_add_test(tc1, test_set_day_limits); - tcase_add_test(tc1, test_set_day_invalid); - suite_add_tcase (s, tc1); - - /* Return created suite */ - return s; -} diff --git a/tests/check_test.c b/tests/check_test.c index c82c438..a701935 100644 --- a/tests/check_test.c +++ b/tests/check_test.c @@ -52,38 +52,11 @@ configure_tests(gint environment) /* Create srunner object with the first test suite */ sr = srunner_create(create_hildon_caption_suite()); -#ifndef HILDON_DISABLE_DEPRECATED - srunner_add_suite(sr, create_hildon_number_editor_suite()); - srunner_add_suite(sr, create_hildon_time_editor_suite()); - srunner_add_suite(sr, create_hildon_time_picker_suite()); - srunner_add_suite(sr, create_hildon_date_editor_suite()); - srunner_add_suite(sr, create_hildon_weekday_picker_suite()); - srunner_add_suite(sr, create_hildon_controlbar_suite()); - srunner_add_suite(sr, create_hildon_color_button_suite()); - srunner_add_suite(sr, create_hildon_color_chooser_suite()); - srunner_add_suite(sr, create_hildon_seekbar_suite()); - /* srunner_add_suite(sr, create_hildon_dialoghelp_suite()); */ - srunner_add_suite(sr, create_hildon_calendar_popup_suite()); - srunner_add_suite(sr, create_hildon_range_editor_suite()); - /* srunner_add_suite(sr, create_hildon_name_password_dialog_suite()); - srunner_add_suite(sr, create_hildon_get_password_dialog_suite()); - srunner_add_suite(sr, create_hildon_set_password_dialog_suite()); */ - srunner_add_suite(sr, create_hildon_sort_dialog_suite()); - srunner_add_suite(sr, create_hildon_code_dialog_suite()); - srunner_add_suite(sr, create_hildon_volumebar_suite()); - srunner_add_suite(sr, create_hildon_volumebar_range_suite()); - srunner_add_suite(sr, create_hildon_font_selection_dialog_suite()); -#endif /* HILDON_DISABLE_DEPRECATED */ srunner_add_suite(sr, create_hildon_find_toolbar_suite()); srunner_add_suite(sr, create_hildon_note_suite()); srunner_add_suite(sr, create_hildon_wizard_dialog_suite()); /* srunner_add_suite(sr, create_hildon_scroll_area_suite()); */ -#ifndef HILDON_DISABLE_DEPRECATED - /* HildonBanner is not deprecated, but all the functions tested in - this suite are deprecated*/ - srunner_add_suite(sr, create_hildon_banner_suite()); -#endif srunner_add_suite(sr, create_hildon_window_suite()); srunner_add_suite(sr, create_hildon_helper_suite()); srunner_add_suite(sr, create_hildon_picker_button_suite()); diff --git a/tests/test_suites.h b/tests/test_suites.h index c0b6b29..93c897b 100644 --- a/tests/test_suites.h +++ b/tests/test_suites.h @@ -51,11 +51,6 @@ Suite *create_hildon_note_suite(void); Suite *create_hildon_volumebar_suite(void); Suite *create_hildon_volumebar_range_suite(void); Suite *create_hildon_wizard_dialog_suite(void); -#ifndef HILDON_DISABLE_DEPRECATED -/* HildonBanner is not deprecated, but all the functions tested in - this suite are deprecated*/ -Suite *create_hildon_banner_suite(void); -#endif Suite *create_hildon_font_selection_dialog_suite(void); Suite *create_hildon_system_sound_suite(void); Suite *create_hildon_scroll_area_suite(void); |