1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright 2009 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
13 #include "deployment.h"
17 SetObjectType (Type::POPUP
);
18 shutting_down
= false;
20 GetDeployment ()->AddHandler (Deployment::ShuttingDownEvent
, ShuttingDownCallback
, this);
26 if (!shutting_down
&& GetIsOpen ())
28 GetDeployment ()->RemoveHandler (Deployment::ShuttingDownEvent
, ShuttingDownCallback
, this);
29 FrameworkElement::Dispose ();
33 Popup::HitTest (cairo_t
*cr
, Point p
, List
*uielement_list
)
36 FrameworkElement::HitTest (cr
, p
, uielement_list
);
40 Popup::OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
)
42 if (args
->GetProperty ()->GetOwnerType() != Type::POPUP
) {
43 FrameworkElement::OnPropertyChanged (args
, error
);
47 if (args
->GetId () == Popup::IsOpenProperty
) {
48 // we intentionally don't track whether we've added a tick
49 // call (to make sure we only add it once) for this event
50 // because multiple IsOpen changes cause multiple async events
52 if (args
->GetNewValue () && args
->GetNewValue ()->AsBool ()) {
55 EmitAsync (Popup::OpenedEvent
);
60 EmitAsync (Popup::ClosedEvent
);
62 } else if (args
->GetId () == Popup::ChildProperty
) {
63 if (args
->GetOldValue () && !args
->GetOldValue ()->GetIsNull ()) {
64 FrameworkElement
*el
= args
->GetOldValue ()->AsFrameworkElement ();
68 el
->SetLogicalParent (NULL
, error
);
72 if (args
->GetNewValue () && !args
->GetNewValue ()->GetIsNull ()) {
73 FrameworkElement
*el
= args
->GetNewValue ()->AsFrameworkElement ();
74 el
->SetLogicalParent (this, error
);
81 } else if (args
->GetId () == Popup::HorizontalOffsetProperty
82 || args
->GetId () == Popup::VerticalOffsetProperty
) {
83 UIElement
* child
= GetChild ();
85 child
->UpdateTransform ();
87 NotifyListenersOfPropertyChange (args
, error
);
91 Popup::ShuttingDownHandler (Deployment
*sender
, EventArgs
*args
)
97 Popup::Hide (UIElement
*child
)
99 if (!visible
|| !child
)
103 Deployment::GetCurrent ()->GetSurface ()->DetachLayer (child
);
104 // When the popup is closed, we signal the child that its parent
105 // is enabled as it no longer has any parent
106 PropagateIsEnabledState (child
, true);
110 Popup::Show (UIElement
*child
)
112 if (visible
|| !child
)
116 Deployment::GetCurrent ()->GetSurface ()->AttachLayer (child
);
117 PropagateIsEnabledState (child
, Control::GetParentEnabledState (this));
121 Popup::PropagateIsEnabledState (UIElement
*child
, bool enabled_parent
)
123 DeepTreeWalker
walker (child
);
124 while (UIElement
*e
= walker
.Step ()) {
125 if (!e
->Is (Type::CONTROL
))
128 Control
*control
= (Control
*) e
;
129 control
->enabled_parent
= enabled_parent
;
130 control
->UpdateEnabled ();
131 walker
.SkipBranch ();