1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright 2007 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
15 #include "collection.h"
16 #include "uielement.h"
19 EventTrigger::EventTrigger ()
21 SetObjectType (Type::EVENTTRIGGER
);
22 registered_event_id
= -1;
25 EventTrigger::~EventTrigger ()
30 EventTrigger::SetTarget (DependencyObject
*target
)
32 g_return_if_fail (target
);
34 #if AT_SOME_POINT_SILVERLIGHT_GETS_ITS_HEAD_OUT_OF_ITS_
35 const char *event
= GetRoutedEvent ();
38 if (event
&& (dot
= strchr (event
, '.'))) {
39 char *type
= g_strndup (event
, dot
-event
);
40 const char *event_name
= dot
+ 1;
42 Type
*event_type
= Type::Find (type
);
46 // event type has to exist
47 if (target
->GetType()->IsSubclassOf (event_type
->GetKind ())) {
48 // the type of the target has
49 // to be a subclass of the
50 // event type for the event to
52 registered_event_id
= event_type
->LookupEvent (event_name
);
56 registered_event_id
= target
->GetType ()->LookupEvent (event
);
59 registered_event_id
= UIElement::LoadedEvent
;
62 if (registered_event_id
== -1)
63 g_warning ("failed to set target");
65 if (registered_event_id
!= -1)
66 target
->AddHandler (registered_event_id
, event_trigger_fire_actions
, this);
70 EventTrigger::RemoveTarget (DependencyObject
*target
)
72 g_return_if_fail (target
);
74 if (registered_event_id
!= -1) {
75 target
->RemoveHandler (registered_event_id
, event_trigger_fire_actions
, this);
76 registered_event_id
= -1;
81 EventTrigger::event_trigger_fire_actions (EventObject
*sender
, EventArgs
*calldata
, gpointer closure
)
83 EventTrigger
*trigger
= (EventTrigger
*) closure
;
85 g_return_if_fail (trigger
);
87 TriggerActionCollection
*actions
= trigger
->GetActions();
89 for (int i
= 0; i
< actions
->GetCount (); i
++) {
90 TriggerAction
*action
= actions
->GetValueAt (i
)->AsTriggerAction ();
97 event_trigger_action_add (EventTrigger
*trigger
, TriggerAction
*action
)
99 trigger
->GetActions()->Add (action
);