From: Alberto Garcia Date: Thu, 28 Aug 2008 18:24:08 +0000 (+0000) Subject: 2008-08-28 Alberto Garcia X-Git-Tag: 2.1.66-1~554 X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=7f34eb740738b8e4502e077f4321e5a15076d079;p=hildon 2008-08-28 Alberto Garcia * doc/hildon-docs.sgml * doc/hildon.types * src/Makefile.am * src/hildon-edit-toolbar.c * src/hildon-edit-toolbar.h * src/hildon.h: New HildonEditToolbar widget. --- diff --git a/ChangeLog b/ChangeLog index 29a1ce3..6151200 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-08-28 Alberto Garcia + + * doc/hildon-docs.sgml + * doc/hildon.types + * src/Makefile.am + * src/hildon-edit-toolbar.c + * src/hildon-edit-toolbar.h + * src/hildon.h: New HildonEditToolbar widget. + 2008-08-28 Claudio Saavedra * examples/hildon-pannable-area-example-4.c: (main): Remove unneeded diff --git a/doc/hildon-docs.sgml b/doc/hildon-docs.sgml index 8e5a822..52913a6 100644 --- a/doc/hildon-docs.sgml +++ b/doc/hildon-docs.sgml @@ -67,6 +67,7 @@ Miscellaneous controls + diff --git a/doc/hildon.types b/doc/hildon.types index 9b15797..a1cde1b 100644 --- a/doc/hildon.types +++ b/doc/hildon.types @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,7 @@ hildon_color_chooser_get_type hildon_controlbar_get_type hildon_date_editor_get_type hildon_find_toolbar_get_type +hildon_edit_toolbar_get_type hildon_font_selection_dialog_get_type hildon_get_password_dialog_get_type hildon_hvolumebar_get_type diff --git a/src/Makefile.am b/src/Makefile.am index 90c99b4..d45b81f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -62,6 +62,7 @@ libhildon_@API_VERSION_MAJOR@_la_SOURCES = \ hildon-color-chooser-dialog.c \ hildon-defines.c \ hildon-find-toolbar.c \ + hildon-edit-toolbar.c \ hildon-banner.c \ hildon-caption.c \ hildon-window.c \ @@ -100,6 +101,7 @@ libhildon_@API_VERSION_MAJOR@_public_headers = \ 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 \ diff --git a/src/hildon-edit-toolbar.c b/src/hildon-edit-toolbar.c new file mode 100644 index 0000000..bb35778 --- /dev/null +++ b/src/hildon-edit-toolbar.c @@ -0,0 +1,213 @@ +/* + * This file is a part of hildon + * + * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; version 2 of the license. + * + * This program 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 Public License for more details. + * + */ + +/** + * SECTION:hildon-edit-toolbar + * @short_description: Widget representing a toolbar for editing. + * + * The #HildonEditToolbar is a toolbar which contains a label and two + * buttons, one of them being an arrow pointing backwards. + * + * The label is a description of the action that the user is supposed + * to do. The button is to be pressed when the user completes the + * action. The arrow is used to go back to the previous view + * discarding any changes. + * + * Note that those widgets don't do anything themselves by default. To + * actually peform actions the developer must provide callbacks for + * them. + */ + +#include "hildon-edit-toolbar.h" +#include "hildon-gtk.h" + +G_DEFINE_TYPE (HildonEditToolbar, hildon_edit_toolbar, GTK_TYPE_HBOX); + +#define HILDON_EDIT_TOOLBAR_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ + HILDON_TYPE_EDIT_TOOLBAR, HildonEditToolbarPrivate)); + +typedef struct _HildonEditToolbarPrivate HildonEditToolbarPrivate; + +struct _HildonEditToolbarPrivate +{ + GtkLabel *label; + GtkButton *button; + GtkButton *arrow; +}; + +enum { + BUTTON_CLICKED, + ARROW_CLICKED, + N_SIGNALS +}; + +static guint toolbar_signals [N_SIGNALS] = { 0 }; + + +static void +hildon_edit_toolbar_class_init (HildonEditToolbarClass *klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + + g_type_class_add_private (klass, sizeof (HildonEditToolbarPrivate)); + + /** + * HildonEditToolbar::button-clicked: + * @widget: the object which received the signal. + * + * Emitted when the toolbar button has been activated (pressed and released). + * + */ + toolbar_signals[BUTTON_CLICKED] = + g_signal_new ("button_clicked", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /** + * HildonEditToolbar::arrow-clicked: + * @widget: the object which received the signal. + * + * Emitted when the toolbar back button (arrow) has been activated + * (pressed and released). + * + */ + toolbar_signals[ARROW_CLICKED] = + g_signal_new ("arrow_clicked", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +static void +button_clicked_cb (GtkButton *self, + HildonEditToolbar *toolbar) +{ + g_signal_emit (toolbar, toolbar_signals[BUTTON_CLICKED], 0); +} + +static void +arrow_clicked_cb (GtkButton *self, + HildonEditToolbar *toolbar) +{ + g_signal_emit (toolbar, toolbar_signals[ARROW_CLICKED], 0); +} + +static void +hildon_edit_toolbar_init (HildonEditToolbar *self) +{ + HildonEditToolbarPrivate *priv = HILDON_EDIT_TOOLBAR_GET_PRIVATE (self); + GtkBox *hbox = GTK_BOX (self); + + priv->label = GTK_LABEL (gtk_label_new (NULL)); + priv->button = GTK_BUTTON (hildon_gtk_button_new (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT)); + priv->arrow = GTK_BUTTON (gtk_button_new ()); + + gtk_button_set_image (priv->arrow, gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_LARGE_TOOLBAR)); + gtk_button_set_relief (priv->arrow, GTK_RELIEF_NONE); + gtk_button_set_focus_on_click (priv->arrow, FALSE); + + g_signal_connect (priv->button, "clicked", G_CALLBACK (button_clicked_cb), self); + g_signal_connect (priv->arrow, "clicked", G_CALLBACK (arrow_clicked_cb), self); + + /* Temporary values, should be replaced by properties or fixed values from the specs */ + gtk_box_set_spacing (hbox, 10); + gtk_widget_set_size_request (GTK_WIDGET (priv->arrow), 50, -1); + + gtk_box_pack_start (hbox, GTK_WIDGET (priv->label), TRUE, TRUE, 0); + gtk_box_pack_start (hbox, GTK_WIDGET (priv->button), FALSE, FALSE, 0); + gtk_box_pack_start (hbox, GTK_WIDGET (priv->arrow), FALSE, FALSE, 0); + + gtk_misc_set_alignment (GTK_MISC (priv->label), 0, 0.5); + + gtk_widget_show (GTK_WIDGET (priv->label)); + gtk_widget_show (GTK_WIDGET (priv->button)); + gtk_widget_show (GTK_WIDGET (priv->arrow)); +} + +/** + * hildon_edit_toolbar_set_label: + * @toolbar: a #HildonEditToolbar + * @label: a new text for the toolbar label + * + * Sets the label of @toolbar to @label. This will clear any + * previously set value. + */ +void +hildon_edit_toolbar_set_label (HildonEditToolbar *toolbar, + const gchar *label) +{ + HildonEditToolbarPrivate *priv; + g_return_if_fail (HILDON_IS_EDIT_TOOLBAR (toolbar)); + priv = HILDON_EDIT_TOOLBAR_GET_PRIVATE (toolbar); + gtk_label_set_text (priv->label, label); +} + +/** + * hildon_edit_toolbar_set_button_label: + * @toolbar: a #HildonEditToolbar + * @label: a new text for the label of the toolbar button + * + * Sets the label of the toolbar button to @label. This will clear any + * previously set value. + */ +void +hildon_edit_toolbar_set_button_label (HildonEditToolbar *toolbar, + const gchar *label) +{ + HildonEditToolbarPrivate *priv; + g_return_if_fail (HILDON_IS_EDIT_TOOLBAR (toolbar)); + priv = HILDON_EDIT_TOOLBAR_GET_PRIVATE (toolbar); + gtk_button_set_label (priv->button, label); +} + +/** + * hildon_edit_toolbar_new: + * + * Creates a new #HildonEditToolbar. + * + * Returns: a new #HildonEditToolbar + */ +GtkWidget * +hildon_edit_toolbar_new (void) +{ + return g_object_new (HILDON_TYPE_EDIT_TOOLBAR, NULL); +} + +/** + * hildon_edit_toolbar_new_with_text: + * + * Creates a new #HildonEditToolbar, with the toolbar label set to + * @label and the button label set to @button. + * + * Returns: a new #HildonEditToolbar + */ +GtkWidget * +hildon_edit_toolbar_new_with_text (const gchar *label, + const gchar *button) +{ + GtkWidget *toolbar = g_object_new (HILDON_TYPE_EDIT_TOOLBAR, NULL); + + hildon_edit_toolbar_set_label (HILDON_EDIT_TOOLBAR (toolbar), label); + hildon_edit_toolbar_set_button_label (HILDON_EDIT_TOOLBAR (toolbar), button); + + return toolbar; +} diff --git a/src/hildon-edit-toolbar.h b/src/hildon-edit-toolbar.h new file mode 100644 index 0000000..a93e7e1 --- /dev/null +++ b/src/hildon-edit-toolbar.h @@ -0,0 +1,79 @@ +/* + * This file is a part of hildon + * + * Copyright (C) 2008 Nokia Corporation, all rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; version 2 of the license. + * + * This program 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 Public License for more details. + * + */ + +#ifndef __HILDON_EDIT_TOOLBAR_H__ +#define __HILDON_EDIT_TOOLBAR_H__ + +#include + +G_BEGIN_DECLS + +#define HILDON_TYPE_EDIT_TOOLBAR \ + (hildon_edit_toolbar_get_type()) + +#define HILDON_EDIT_TOOLBAR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + HILDON_TYPE_EDIT_TOOLBAR, HildonEditToolbar)) + +#define HILDON_EDIT_TOOLBAR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + HILDON_TYPE_EDIT_TOOLBAR, HildonEditToolbarClass)) + +#define HILDON_IS_EDIT_TOOLBAR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HILDON_TYPE_EDIT_TOOLBAR)) + +#define HILDON_IS_EDIT_TOOLBAR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), HILDON_TYPE_EDIT_TOOLBAR)) + +#define HILDON_EDIT_TOOLBAR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + HILDON_TYPE_EDIT_TOOLBAR, HildonEditToolbarClass)) + +typedef struct _HildonEditToolbar HildonEditToolbar; + +typedef struct _HildonEditToolbarClass HildonEditToolbarClass; + +struct _HildonEditToolbarClass +{ + GtkHBoxClass parent_class; +}; + +struct _HildonEditToolbar +{ + GtkHBox parent; +}; + +GType +hildon_edit_toolbar_get_type (void) G_GNUC_CONST; + +GtkWidget * +hildon_edit_toolbar_new (void); + +GtkWidget * +hildon_edit_toolbar_new_with_text (const gchar *label, + const gchar *button); + +void +hildon_edit_toolbar_set_label (HildonEditToolbar *toolbar, + const gchar *label); + +void +hildon_edit_toolbar_set_button_label (HildonEditToolbar *toolbar, + const gchar *label); + +G_END_DECLS + +#endif /* __HILDON_EDIT_TOOLBAR_H__ */ diff --git a/src/hildon.h b/src/hildon.h index 66bb3d8..38a793e 100644 --- a/src/hildon.h +++ b/src/hildon.h @@ -39,6 +39,7 @@ #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"