aboutsummaryrefslogtreecommitdiffstats
path: root/a11y/e-table/gal-a11y-e-table-click-to-add.c
diff options
context:
space:
mode:
Diffstat (limited to 'a11y/e-table/gal-a11y-e-table-click-to-add.c')
-rw-r--r--a11y/e-table/gal-a11y-e-table-click-to-add.c270
1 files changed, 270 insertions, 0 deletions
diff --git a/a11y/e-table/gal-a11y-e-table-click-to-add.c b/a11y/e-table/gal-a11y-e-table-click-to-add.c
new file mode 100644
index 0000000000..1b55d526df
--- /dev/null
+++ b/a11y/e-table/gal-a11y-e-table-click-to-add.c
@@ -0,0 +1,270 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Yuedong Du <yuedong.du@sun.com>
+ *
+ * Copyright (C) 2002 Ximian, Inc.
+ */
+
+#include <config.h>
+#include "gal-a11y-util.h"
+#include "gal-a11y-e-table-click-to-add.h"
+#include <gal/e-table/e-table-group.h>
+#include <gal/e-table/e-table-group-leaf.h>
+#include <gal/e-table/e-table-click-to-add.h>
+#include <atk/atkcomponent.h>
+#include <atk/atkaction.h>
+
+static AtkObjectClass *parent_class;
+static GType parent_type;
+static gint priv_offset;
+#define GET_PRIVATE(object) ((GalA11yETableClickToAddPrivate *) (((char *) object) + priv_offset))
+#define PARENT_TYPE (parent_type)
+
+struct _GalA11yETableClickToAddPrivate {
+ gpointer rect;
+ gpointer row;
+};
+
+
+static gint
+etcta_get_n_actions (AtkAction *action)
+{
+ return 1;
+}
+
+static G_CONST_RETURN gchar*
+etcta_get_description (AtkAction *action,
+ gint i)
+{
+ if (i == 0)
+ return "click to add";
+
+ return NULL;
+}
+
+static G_CONST_RETURN gchar*
+etcta_action_get_name (AtkAction *action, gint i)
+{
+ if (i == 0)
+ return "click";
+
+ return NULL;
+}
+
+
+static gboolean
+idle_do_action (gpointer data)
+{
+ GdkEventButton event;
+ ETableClickToAdd * etcta;
+ gint x, y, width, height, finished;
+
+ g_return_val_if_fail ( data!= NULL, FALSE);
+
+ etcta = atk_gobject_accessible_get_object (ATK_OBJECT(data));
+ g_return_val_if_fail (etcta, FALSE);
+
+ event.x = 0;
+ event.y = 0;
+
+ event.type = GDK_BUTTON_PRESS;
+ event.window = GTK_LAYOUT(GNOME_CANVAS_ITEM(etcta)->canvas)->bin_window;
+ event.button = 1;
+ event.send_event = TRUE;
+ event.time = GDK_CURRENT_TIME;
+ event.axes = NULL;
+
+ g_signal_emit_by_name (etcta, "event", &event, &finished);
+
+ return FALSE;
+}
+
+static gboolean
+etcta_do_action (AtkAction * action, gint i)
+{
+ g_return_val_if_fail (i == 0, FALSE);
+
+ g_idle_add (idle_do_action, action);
+
+ return TRUE;
+}
+
+static void
+atk_action_interface_init (AtkActionIface *iface)
+{
+ g_return_if_fail (iface != NULL);
+
+ iface->do_action = etcta_do_action;
+ iface->get_n_actions = etcta_get_n_actions;
+ iface->get_description = etcta_get_description;
+ iface->get_name = etcta_action_get_name;
+}
+
+
+static G_CONST_RETURN gchar *
+etcta_get_name (AtkObject *obj)
+{
+ g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_CLICK_TO_ADD (obj), NULL);
+
+ return "click to add";
+}
+
+static gint
+etcta_get_n_children (AtkObject *accessible)
+{
+ return 1;
+}
+
+static AtkObject*
+etcta_ref_child (AtkObject *accessible,
+ gint i)
+{
+ AtkObject * atk_obj = NULL;
+ ETableClickToAdd * etcta;
+
+ if ( i != 0 )
+ return NULL;
+
+ etcta = E_TABLE_CLICK_TO_ADD(atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
+
+ g_return_if_fail (etcta);
+
+ if (etcta->rect) {
+ atk_obj = atk_gobject_accessible_for_object (G_OBJECT(etcta->rect));
+ } else if (etcta->row) {
+ atk_obj = atk_gobject_accessible_for_object (G_OBJECT(etcta->row));
+ }
+
+ g_object_ref (atk_obj);
+
+ return atk_obj;
+}
+
+static void
+etcta_class_init (GalA11yETableClickToAddClass *klass)
+{
+ AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_ref (PARENT_TYPE);
+
+ atk_object_class->get_name = etcta_get_name;
+ atk_object_class->get_n_children = etcta_get_n_children;
+ atk_object_class->ref_child = etcta_ref_child;
+}
+
+static void
+etcta_init (GalA11yETableClickToAdd *a11y)
+{
+}
+
+/**
+ * gal_a11y_e_table_click_to_add_get_type:
+ * @void:
+ *
+ * Registers the &GalA11yETableClickToAdd class if necessary, and returns the type ID
+ * associated to it.
+ *
+ * Return value: The type ID of the &GalA11yETableClickToAdd class.
+ **/
+GType
+gal_a11y_e_table_click_to_add_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type) {
+ AtkObjectFactory *factory;
+
+ GTypeInfo info = {
+ sizeof (GalA11yETableClickToAddClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) etcta_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (GalA11yETableClickToAdd),
+ 0,
+ (GInstanceInitFunc) etcta_init,
+ NULL /* value_table */
+ };
+
+ static const GInterfaceInfo atk_action_info = {
+ (GInterfaceInitFunc) atk_action_interface_init,
+ (GInterfaceFinalizeFunc) NULL,
+ NULL
+ };
+
+ factory = atk_registry_get_factory (atk_get_default_registry (), GNOME_TYPE_CANVAS_ITEM);
+
+ parent_type = atk_object_factory_get_accessible_type (factory);
+ type = gal_a11y_type_register_static_with_private (PARENT_TYPE,
+ "GalA11yETableClickToAdd", &info, 0,
+ sizeof(GalA11yETableClickToAddPrivate), &priv_offset);
+
+ g_type_add_interface_static (type, ATK_TYPE_ACTION, &atk_action_info);
+
+ }
+
+ return type;
+}
+
+static gboolean
+etcta_event (GnomeCanvasItem *item, GdkEvent *e, gpointer data)
+{
+ ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item);
+ GalA11yETableClickToAdd *a11y;
+ GalA11yETableClickToAddPrivate *priv;
+
+ g_return_val_if_fail (item, TRUE);
+
+ g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_CLICK_TO_ADD(data), FALSE);
+ a11y = GAL_A11Y_E_TABLE_CLICK_TO_ADD (data);
+
+ priv = GET_PRIVATE (a11y);
+
+ /* rect replaced by row. */
+ if (etcta->rect == NULL && priv->rect != NULL) {
+ g_signal_emit_by_name (a11y, "children_changed::remove", 0, NULL, NULL);
+
+ }
+ /* row inserted, and/or replaced by a new row. */
+ if (etcta->row != NULL && priv->row == NULL) {
+ g_signal_emit_by_name (a11y, "children_changed::add", 0, NULL, NULL);
+ } else if (etcta->row != NULL && priv->row != NULL && etcta->row != priv->row) {
+ g_signal_emit_by_name (a11y, "children_changed::remove", 0, NULL, NULL);
+ g_signal_emit_by_name (a11y, "children_changed::add", 0, NULL, NULL);
+ }
+
+
+ priv->rect = etcta->rect;
+ priv->row = etcta->row;
+
+ return TRUE;
+}
+
+AtkObject *
+gal_a11y_e_table_click_to_add_new (GObject *widget)
+{
+ GalA11yETableClickToAdd *a11y;
+ ETableClickToAdd * etcta;
+ GalA11yETableClickToAddPrivate *priv;
+ gint id;
+
+ g_return_if_fail (widget != NULL);
+
+ a11y = g_object_new (gal_a11y_e_table_click_to_add_get_type (), NULL);
+ priv = GET_PRIVATE (a11y);
+
+ etcta = E_TABLE_CLICK_TO_ADD(widget);
+
+
+ atk_object_initialize (ATK_OBJECT (a11y), etcta);
+
+ priv->rect = etcta->rect;
+ priv->row = etcta->row;
+
+
+ g_signal_connect_after (G_OBJECT(widget), "event",
+ G_CALLBACK (etcta_event), a11y);
+
+ return ATK_OBJECT (a11y);
+}
ail because there will not be enough gas to finish the execution of the fallback function. .. index:: access;restricting ****************** Restricting Access ****************** Restricting access is a common pattern for contracts. Note that you can never restrict any human or computer from reading the content of your transactions or your contract's state. You can make it a bit harder by using encryption, but if your contract is supposed to read the data, so will everyone else. You can restrict read access to your contract's state by **other contracts**. That is actually the default unless you declare make your state variables ``public``. Furthermore, you can restrict who can make modifications to your contract's state or call your contract's functions and this is what this page is about. .. index:: function;modifier The use of **function modifiers** makes these restrictions highly readable. :: pragma solidity ^0.4.0; contract AccessRestriction { // These will be assigned at the construction // phase, where `msg.sender` is the account // creating this contract. address public owner = msg.sender; uint public creationTime = now; // Modifiers can be used to change // the body of a function. // If this modifier is used, it will // prepend a check that only passes // if the function is called from // a certain address. modifier onlyBy(address _account) { if (msg.sender != _account) throw; // Do not forget the "_;"! It will // be replaced by the actual function // body when the modifier is used. _; } /// Make `_newOwner` the new owner of this /// contract. function changeOwner(address _newOwner) onlyBy(owner) { owner = _newOwner; } modifier onlyAfter(uint _time) { if (now < _time) throw; _; } /// Erase ownership information. /// May only be called 6 weeks after /// the contract has been created. function disown() onlyBy(owner) onlyAfter(creationTime + 6 weeks) { delete owner; } // This modifier requires a certain // fee being associated with a function call. // If the caller sent too much, he or she is // refunded, but only after the function body. // This was dangerous before Solidity version 0.4.0, // where it was possible to skip the part after `_;`. modifier costs(uint _amount) { if (msg.value < _amount) throw; _; if (msg.value > _amount) msg.sender.send(msg.value - _amount); } function forceOwnerChange(address _newOwner) costs(200 ether) { owner = _newOwner; // just some example condition if (uint(owner) & 0 == 1) // This did not refund for Solidity // before version 0.4.0. return; // refund overpaid fees } } A more specialised way in which access to function calls can be restricted will be discussed in the next example. .. index:: state machine ************* State Machine ************* Contracts often act as a state machine, which means that they have certain **stages** in which they behave differently or in which different functions can be called. A function call often ends a stage and transitions the contract into the next stage (especially if the contract models **interaction**). It is also common that some stages are automatically reached at a certain point in **time**. An example for this is a blind auction contract which starts in the stage "accepting blinded bids", then transitions to "revealing bids" which is ended by "determine auction autcome". .. index:: function;modifier Function modifiers can be used in this situation to model the states and guard against incorrect usage of the contract. Example ======= In the following example, the modifier ``atStage`` ensures that the function can only be called at a certain stage. Automatic timed transitions are handled by the modifier ``timeTransitions``, which should be used for all functions. .. note:: **Modifier Order Matters**. If atStage is combined with timedTransitions, make sure that you mention it after the latter, so that the new stage is taken into account. Finally, the modifier ``transitionNext`` can be used to automatically go to the next stage when the function finishes. .. note:: **Modifier May be Skipped**. This only applies to Solidity before version 0.4.0: Since modifiers are applied by simply replacing code and not by using a function call, the code in the transitionNext modifier can be skipped if the function itself uses return. If you want to do that, make sure to call nextStage manually from those functions. Starting with version 0.4.0, modifier code will run even if the function explicitly returns. :: pragma solidity ^0.4.0; contract StateMachine { enum Stages { AcceptingBlindedBids, RevealBids, AnotherStage, AreWeDoneYet, Finished } // This is the current stage. Stages public stage = Stages.AcceptingBlindedBids; uint public creationTime = now; modifier atStage(Stages _stage) { if (stage != _stage) throw; _; } function nextStage() internal { stage = Stages(uint(stage) + 1); } // Perform timed transitions. Be sure to mention // this modifier first, otherwise the guards // will not take the new stage into account. modifier timedTransitions() { if (stage == Stages.AcceptingBlindedBids && now >= creationTime + 10 days) nextStage(); if (stage == Stages.RevealBids && now >= creationTime + 12 days) nextStage(); // The other stages transition by transaction _; } // Order of the modifiers matters here! function bid() payable timedTransitions atStage(Stages.AcceptingBlindedBids) { // We will not implement that here } function reveal() timedTransitions atStage(Stages.RevealBids) { } // This modifier goes to the next stage // after the function is done. modifier transitionNext() { _; nextStage(); } function g() timedTransitions atStage(Stages.AnotherStage) transitionNext { } function h() timedTransitions atStage(Stages.AreWeDoneYet) transitionNext { } function i() timedTransitions atStage(Stages.Finished) { } }